tracing: significantly improve code generation at trace points #3398
+126
−121
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: