tracing: significantly improve code generation at trace points#3398
Merged
hds merged 3 commits intotokio-rs:mainfrom Nov 19, 2025
Merged
tracing: significantly improve code generation at trace points#3398hds merged 3 commits intotokio-rs:mainfrom
hds merged 3 commits intotokio-rs:mainfrom
Conversation
Contributor
Author
|
Test and clippy failures are pre-existing. But the test failure is a little alarming since it's in the area that I'm changing. Looking into it. |
Contributor
Author
|
I see the test bug. Someone regressed the test last year while cleaning up warnings. I will open a separate PR to fix this. |
Contributor
Author
1f6c9aa to
48ce86e
Compare
martin-g
reviewed
Nov 11, 2025
hds
reviewed
Nov 16, 2025
Contributor
hds
left a comment
There was a problem hiding this comment.
Thank you for your PR!
Question on the naming. But otherwise this looks good.
`ValueSet`s contain both a `FieldSet` reference and a slice of (`&Field`, `Option<&dyn Value>`) pairs. In cases where `ValueSet`s are generated via documented interfaces (specifically, `tracing::event!` and other macros), the `Field` references are redundant, because the `ValueSet` contains a value slot for every field (either a value or `None`), in the correct order. As a result, the code generated by the macros is terrible--it must put a `Field` on the stack for each field--that's 32 bytes per field! This is a lot of work for apparently no purpose at runtime, and it can't be moved into a read-only data section since it's intermixed with dynamic data. Fix this by adding a variant of `ValueSet` that skips the `Field` references, knowing that it represents the full set of fields. Keep the old kind of `ValueSet`, too--it's still needed by `Span::record`, by old versions of crates, and potentially by third-party crates using undocumented methods such as `FieldSet::value_set`. In some adhoc tests on x86_64 Linux, this reduces the code size as follows: * One-field event: 258 bytes to 189 bytes, 25% reduction. * Five-field event: 638 bytes to 276 bytes, **57%** reduction. * In a larger project with lots of events, ~5% reduction in .text section.
Contributor
|
I've rebased and fixed some conflicts introduced by #3382. |
hds
approved these changes
Nov 19, 2025
Contributor
hds
left a comment
There was a problem hiding this comment.
Thank you for this PR! It's a great idea!
hds
added a commit
that referenced
this pull request
Nov 24, 2025
# 0.1.35 (November 24, 2025) ### Added - Switch to unconditional `no_std` ([#3323]) - Improve code generation at trace points significantly ([#3398]) ### Fixed - Add missing `dyn` keyword in `Visit` documentation code sample ([#3387]) ### Documented - Add favicon for extra pretty docs ([#3351]) [#3323]: https://github.com/tokio-rs/tracing/pull/#3323 [#3351]: https://github.com/tokio-rs/tracing/pull/#3351 [#3387]: https://github.com/tokio-rs/tracing/pull/#3387 [#3398]: https://github.com/tokio-rs/tracing/pull/#3398
hds
added a commit
that referenced
this pull request
Nov 24, 2025
# 0.1.35 (November 24, 2025) ### Added - Switch to unconditional `no_std` ([#3323]) - Improve code generation at trace points significantly ([#3398]) ### Fixed - Add missing `dyn` keyword in `Visit` documentation code sample ([#3387]) ### Documented - Add favicon for extra pretty docs ([#3351]) [#3323]: https://github.com/tokio-rs/tracing/pull/#3323 [#3351]: https://github.com/tokio-rs/tracing/pull/#3351 [#3387]: https://github.com/tokio-rs/tracing/pull/#3387 [#3398]: https://github.com/tokio-rs/tracing/pull/#3398
hds
added a commit
that referenced
this pull request
Nov 25, 2025
# 0.1.42 (November 30, 2025) ### Added - **attributes**: Support constant expressions as instrument field names ([#3158]) - **core**: Improve code generation at trace points significantly ([#3398]) ### Fixed - Fix perf regression when `release_max_level_*` not set ([#3373]) - Use imported instead of fully qualified path ([#3374]) - Make `valueset` macro sanitary ([#3382]) ### Documented - **core**: Add missing `dyn` keyword in `Visit` documentation code sample ([#3387]) [#3158]: https://github.com/tokio-rs/tracing/pull/#3158 [#3373]: https://github.com/tokio-rs/tracing/pull/#3373 [#3374]: https://github.com/tokio-rs/tracing/pull/#3374 [#3382]: https://github.com/tokio-rs/tracing/pull/#3382 [#3387]: https://github.com/tokio-rs/tracing/pull/#3387 [#3398]: https://github.com/tokio-rs/tracing/pull/#3398
hds
added a commit
that referenced
this pull request
Nov 26, 2025
# 0.1.35 (November 26, 2025) ### Added - Switch to unconditional `no_std` ([#3323]) - Improve code generation at trace points significantly ([#3398]) ### Fixed - Add missing `dyn` keyword in `Visit` documentation code sample ([#3387]) ### Documented - Add favicon for extra pretty docs ([#3351]) [#3323]: https://github.com/tokio-rs/tracing/pull/#3323 [#3351]: https://github.com/tokio-rs/tracing/pull/#3351 [#3387]: https://github.com/tokio-rs/tracing/pull/#3387 [#3398]: https://github.com/tokio-rs/tracing/pull/#3398
hds
added a commit
that referenced
this pull request
Nov 26, 2025
# 0.1.35 (November 26, 2025) ### Added - Switch to unconditional `no_std` ([#3323]) - Improve code generation at trace points significantly ([#3398]) ### Fixed - Add missing `dyn` keyword in `Visit` documentation code sample ([#3387]) ### Documented - Add favicon for extra pretty docs ([#3351]) [#3323]: https://github.com/tokio-rs/tracing/pull/#3323 [#3351]: https://github.com/tokio-rs/tracing/pull/#3351 [#3387]: https://github.com/tokio-rs/tracing/pull/#3387 [#3398]: https://github.com/tokio-rs/tracing/pull/#3398
hds
added a commit
that referenced
this pull request
Nov 26, 2025
# 0.1.35 (November 26, 2025) ### Added - Switch to unconditional `no_std` ([#3323]) - Improve code generation at trace points significantly ([#3398]) ### Fixed - Add missing `dyn` keyword in `Visit` documentation code sample ([#3387]) ### Documented - Add favicon for extra pretty docs ([#3351]) [#3323]: https://github.com/tokio-rs/tracing/pull/#3323 [#3351]: https://github.com/tokio-rs/tracing/pull/#3351 [#3387]: https://github.com/tokio-rs/tracing/pull/#3387 [#3398]: https://github.com/tokio-rs/tracing/pull/#3398
hds
added a commit
that referenced
this pull request
Nov 26, 2025
# 0.1.42 (November 26, 2025) ### Added - **attributes**: Support constant expressions as instrument field names ([#3158]) - **core**: Improve code generation at trace points significantly ([#3398]) ### Changed - `tracing-core`: updated to 0.1.35 ([#3414]) - `tracing-attributes`: updated to 0.1.31 ([#3417]) ### Fixed - Fix perf regression when `release_max_level_*` not set ([#3373]) - Use imported instead of fully qualified path ([#3374]) - Make `valueset` macro sanitary ([#3382]) ### Documented - **core**: Add missing `dyn` keyword in `Visit` documentation code sample ([#3387]) [#3158]: https://github.com/tokio-rs/tracing/pull/#3158 [#3373]: https://github.com/tokio-rs/tracing/pull/#3373 [#3374]: https://github.com/tokio-rs/tracing/pull/#3374 [#3382]: https://github.com/tokio-rs/tracing/pull/#3382 [#3387]: https://github.com/tokio-rs/tracing/pull/#3387 [#3398]: https://github.com/tokio-rs/tracing/pull/#3398 [#3414]: https://github.com/tokio-rs/tracing/pull/#3414 [#3417]: https://github.com/tokio-rs/tracing/pull/#3417
hds
added a commit
that referenced
this pull request
Nov 26, 2025
# 0.1.42 (November 26, 2025) ### Added - **attributes**: Support constant expressions as instrument field names ([#3158]) - Add `record_all!` macro for recording multiple values in one call ([#3227]) - **core**: Improve code generation at trace points significantly ([#3398]) ### Changed - `tracing-core`: updated to 0.1.35 ([#3414]) - `tracing-attributes`: updated to 0.1.31 ([#3417]) ### Fixed - Fix "name / parent" variant of `event!` ([#2983]) - Remove 'r#' prefix from raw identifiers in field names ([#3130]) - Fix perf regression when `release_max_level_*` not set ([#3373]) - Use imported instead of fully qualified path ([#3374]) - Make `valueset` macro sanitary ([#3382]) ### Documented - **core**: Add missing `dyn` keyword in `Visit` documentation code sample ([#3387]) [#2983]: https://github.com/tokio-rs/tracing/pull/#2983 [#3130]: https://github.com/tokio-rs/tracing/pull/#3130 [#3158]: https://github.com/tokio-rs/tracing/pull/#3158 [#3227]: https://github.com/tokio-rs/tracing/pull/#3227 [#3373]: https://github.com/tokio-rs/tracing/pull/#3373 [#3374]: https://github.com/tokio-rs/tracing/pull/#3374 [#3382]: https://github.com/tokio-rs/tracing/pull/#3382 [#3387]: https://github.com/tokio-rs/tracing/pull/#3387 [#3398]: https://github.com/tokio-rs/tracing/pull/#3398 [#3414]: https://github.com/tokio-rs/tracing/pull/#3414 [#3417]: https://github.com/tokio-rs/tracing/pull/#3417
hds
added a commit
that referenced
this pull request
Nov 26, 2025
# 0.1.42 (November 26, 2025) ### Important The [`Span::record_all`] method has been removed from the documented API. It was always unsuable via the documented API as it requried a `ValueSet` which has no publically documented constructors. The method remains, but should not be used outside of `tracing` macros. ### Added - **attributes**: Support constant expressions as instrument field names ([#3158]) - Add `record_all!` macro for recording multiple values in one call ([#3227]) - **core**: Improve code generation at trace points significantly ([#3398]) ### Changed - `tracing-core`: updated to 0.1.35 ([#3414]) - `tracing-attributes`: updated to 0.1.31 ([#3417]) ### Fixed - Fix "name / parent" variant of `event!` ([#2983]) - Remove 'r#' prefix from raw identifiers in field names ([#3130]) - Fix perf regression when `release_max_level_*` not set ([#3373]) - Use imported instead of fully qualified path ([#3374]) - Make `valueset` macro sanitary ([#3382]) ### Documented - **core**: Add missing `dyn` keyword in `Visit` documentation code sample ([#3387]) [#2983]: https://github.com/tokio-rs/tracing/pull/#2983 [#3130]: https://github.com/tokio-rs/tracing/pull/#3130 [#3158]: https://github.com/tokio-rs/tracing/pull/#3158 [#3227]: https://github.com/tokio-rs/tracing/pull/#3227 [#3373]: https://github.com/tokio-rs/tracing/pull/#3373 [#3374]: https://github.com/tokio-rs/tracing/pull/#3374 [#3382]: https://github.com/tokio-rs/tracing/pull/#3382 [#3387]: https://github.com/tokio-rs/tracing/pull/#3387 [#3398]: https://github.com/tokio-rs/tracing/pull/#3398 [#3414]: https://github.com/tokio-rs/tracing/pull/#3414 [#3417]: https://github.com/tokio-rs/tracing/pull/#3417 [`Span::record_all`]: https://docs.rs/tracing/0.1.41/tracing/struct.Span.html#method.record_all
hds
added a commit
that referenced
this pull request
Nov 26, 2025
# 0.1.42 (November 26, 2025) ### Important The [`Span::record_all`] method has been removed from the documented API. It was always unsuable via the documented API as it requried a `ValueSet` which has no publically documented constructors. The method remains, but should not be used outside of `tracing` macros. ### Added - **attributes**: Support constant expressions as instrument field names ([#3158]) - Add `record_all!` macro for recording multiple values in one call ([#3227]) - **core**: Improve code generation at trace points significantly ([#3398]) ### Changed - `tracing-core`: updated to 0.1.35 ([#3414]) - `tracing-attributes`: updated to 0.1.31 ([#3417]) ### Fixed - Fix "name / parent" variant of `event!` ([#2983]) - Remove 'r#' prefix from raw identifiers in field names ([#3130]) - Fix perf regression when `release_max_level_*` not set ([#3373]) - Use imported instead of fully qualified path ([#3374]) - Make `valueset` macro sanitary ([#3382]) ### Documented - **core**: Add missing `dyn` keyword in `Visit` documentation code sample ([#3387]) [#2983]: https://github.com/tokio-rs/tracing/pull/#2983 [#3130]: https://github.com/tokio-rs/tracing/pull/#3130 [#3158]: https://github.com/tokio-rs/tracing/pull/#3158 [#3227]: https://github.com/tokio-rs/tracing/pull/#3227 [#3373]: https://github.com/tokio-rs/tracing/pull/#3373 [#3374]: https://github.com/tokio-rs/tracing/pull/#3374 [#3382]: https://github.com/tokio-rs/tracing/pull/#3382 [#3387]: https://github.com/tokio-rs/tracing/pull/#3387 [#3398]: https://github.com/tokio-rs/tracing/pull/#3398 [#3414]: https://github.com/tokio-rs/tracing/pull/#3414 [#3417]: https://github.com/tokio-rs/tracing/pull/#3417 [`Span::record_all`]: https://docs.rs/tracing/0.1.41/tracing/struct.Span.html#method.record_all
conradludgate
added a commit
to conradludgate/tracing
that referenced
this pull request
Nov 28, 2025
conradludgate
added a commit
to conradludgate/tracing
that referenced
this pull request
Nov 28, 2025
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.
ValueSets contain both aFieldSetreference and a slice of (&Field,Option<&dyn Value>) pairs. In cases whereValueSets are generated via documented interfaces (specifically,tracing::event!and other macros), theFieldreferences are redundant, because theValueSetcontains a value slot for every field (either a value orNone), in the correct order.As a result, the code generated by the macros is terrible--it must put a
Fieldon the stack for each field--that's 32 bytes per field! This is a lot of work for apparently no purpose at runtime, and it can't be moved into a read-only data section since it's intermixed with dynamic data.Fix this by adding a variant of
ValueSetthat skips theFieldreferences, knowing that it represents the full set of fields. Keep the old kind ofValueSet, too--it's still needed bySpan::record, by old versions of crates, and potentially by third-party crates using undocumented methods such asFieldSet::value_set.In some adhoc tests on x86_64 Linux, this reduces the code size as follows: