Skip to content

Comments

Avoid unnecessary overhead from logging#4191

Open
MartinquaXD wants to merge 5 commits intomainfrom
optimize-logging
Open

Avoid unnecessary overhead from logging#4191
MartinquaXD wants to merge 5 commits intomainfrom
optimize-logging

Conversation

@MartinquaXD
Copy link
Contributor

@MartinquaXD MartinquaXD commented Feb 20, 2026

Description

To my surprise do tracing macros not lazily evaluate expressions. So in following code:

        tracing::trace!(
            path = &url.path(),
            body = %payload.body_to_string(),
            "solver request",
        );

payload.body_to_string() always gets evaluated but the Display implementation of the resulting String gets called only when the log is enabled.
This leads to the autopilot currently spending ~2% of the time in body_to_string().

To address this I introduced the Lazy type that delays the execution of the passed in expression to when the tracing machinery actually executed the Display or Debug functionality.

Additionally flamegraphs showed that the driver is currently burning 2.2% of its CPU time on logging auction deadlines. I downgraded that log to trace since it's not really that useful.

Changes

used Lazy in the autopilot
downgraded expensive log to trace

Test

Manually tested that body_to_string() does not get called by injecting a panic!() without causing tests to fail
added unit tests for Lazy in observe crate

@MartinquaXD MartinquaXD requested a review from a team as a code owner February 20, 2026 20:00
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request effectively addresses the identified performance overhead from eager logging by introducing a Lazy type and downgrading a frequently called log level. The changes are well-implemented and include unit tests for the new Lazy type. The use of Lazy for payload.body_to_string() is a good optimization, and the log level adjustment for computed deadline will reduce CPU burn. No critical issues found.

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.

1 participant