Repository navigation
Keep log_impl out of callsites - #751
Closed
patrick-immometrica wants to merge 2 commits into
Closed
patrick-immometrica wants to merge 2 commits into
patrick-immometrica wants to merge 2 commits into
Conversation
Since the logger param was added log_impl is generic, so it's compiled in the calling crate and inlined there. Every log statement then builds the whole Record itself.
A tuple holding the result of loc() can't be promoted to a static, so it was written to the stack before each call. Without it the target and module path are a constant again whenever the target is one.
patrick-immometrica
marked this pull request as ready for review
November 15, 2026 18:49
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.
log_implis commented as "split fromlogto reduce generics and code size", but since #664 it's generic over the logger. So it's instantiated in the calling crate and LLVM inlines it there, and every log statement builds the wholeRecordat the callsite.The first commit marks it
#[inline(never)]. The global logger is still passed as a ZST.The second commit passes the location as its own argument.
&(target, module_path!(), loc())can't be promoted to a static because of theloc()call, so since #633 the tuple is written to the stack before each call. This only makes a difference together with the first commit, on its own the size is the same as on main.Measured with a workspace of 3 crates with 300 log statements each and a logger that does nothing (release build, Rust 1.99.1):
__textaarch64-apple-darwin__textx86_64-apple-darwinThat's about 45 bytes less per log statement on aarch64 and 90 on x86_64. An enabled record gets about 0.3 ns slower than on main, because the record isn't built from constants at the callsite anymore.