Skip to content

Conversation

@febo
Copy link
Collaborator

@febo febo commented Nov 4, 2024

Problem

Currently, logging messages that require formatting are a bit heavy on the CU consumption. For example, a simple msg!("lamports={}", lamports) log can take ~627 CUs.

Solution

Create a lightweight log! macro that improves CU consumption.

  • log! macro
  • Log trait to define custom logic for formatting/logging
  • pinocchio-log crate
  • Optimize and measure CU

Below is a sample of the improvements observed when formatting log messages, measured in terms of compute units (CU):

Ouput message log! msg! Improvement (%)
"Hello world!" 103 103 -
"lamports={}" + u64 374 627 (+253) 40%
"{}" + [&str; 2] 384 1648 (+1264) 76%
"{}" + [u64; 2] 601 1060 (+459) 44%
"lamports={}" + i64 389 660 (+271) 41%
"{}" + [u8; 32] (pubkey bytes) 3147 8401 (+5254) 62%

@febo febo marked this pull request as ready for review November 10, 2024 12:19
@febo febo merged commit 40cb22a into main Nov 10, 2024
3 checks passed
@febo febo deleted the febo/log branch November 10, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants