Format log context only when a line is logged - #98
Open
WYCLIFF001 wants to merge 1 commit into
Open
WYCLIFF001 wants to merge 1 commit into
WYCLIFF001 wants to merge 1 commit into
Conversation
The session loop built the `local { seq, ack }` string and the header
description for every packet, and poll_write another string for every
held write, whatever the log level. At the default level none of them is
ever printed, so every packet paid for an allocation and a format that
went unused. The context is now a value that formats itself when a log
line is emitted, and the header description is built only when trace is
enabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The session loop builds
format!("local {{ seq: {seq}, ack: {ack} }}")andtcp_header_fmt(tcp_header)for every packet, andpoll_writebuilds another string for every held write, whatever the log level. At the default level none of them is printed, so every packet pays for allocations and formatting that go unused. In a profile of a 600 Mbit/s tunnel these showed up ascore::fmtplus the matchingmalloc/freeon every packet.l_infois now a smallLocalInfo(seq, ack)value that implementsDisplay, so it formats only inside a log line that is actually emitted. The six call sites are unchanged apart from the constructor.log::log_enabled!(log::Level::Trace).trace!.Log output is identical at every level.
cargo fmt --check,cargo clippy --all-targets(no warnings) andcargo testpass.🤖 Generated with Claude Code