sdk: optimize composite attribute truncation - #8912
Open
pellared wants to merge 11 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8912 +/- ##
======================================
Coverage 88.5% 88.6%
======================================
Files 331 333 +2
Lines 21090 21283 +193
======================================
+ Hits 18681 18869 +188
- Misses 2409 2414 +5
🚀 New features to boost your workflow:
|
pellared
marked this pull request as ready for review
September 1, 2026 11:22
pellared
requested review from
MrAlias,
XSAM,
dashpole,
dmathieu and
flc1125
as code owners
September 1, 2026 11:22
XSAM
approved these changes
Sep 6, 2026
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.
Changes
STRINGSLICE,SLICE, andMAPattribute values in the Trace and Logs SDK truncation paths.Performance analysis
The previous implementation materialized defensive copies through
AsStringSlice,AsSlice, orAsMapeven when a finite configured limit did not truncate anything. Nested values that did change were first searched byneedsTruncationand then walked again to rebuild them, repeatedly revisiting descendants as depth increased.This change reads the immutable array storage using the existing
attrnormraw-storage convention and performs one post-order traversal. Each collection keeps its originalattribute.Valueuntil the first changed child; only then does it allocate a result and backfill the unchanged prefix. Therefore unchanged composite values allocate nothing, while changed nested values rebuild only the affected ancestry. The traversal visits each value once and recursion uses the Go stack, providing O(depth) temporary state without introducing a heap-allocated work stack. Direct top-level scalar and composite dispatch keeps the common wrapper paths from paying an avoidable generic-dispatch call.Highlights from the matched microbenchmark:
STRINGSLICE,SLICE, andMAPvalues fall to 0 B/op and 0 allocs/op for bothValue(Logs) andKeyValue(Trace) entry shapes, including reflection-backed length-6 valuesSTRINGSLICEthat does require truncation retains 2 allocs/op and 64 B/op, but is 36-45% slower in this focused benchmark; this is the cost of the lazy per-element change detection used to eliminate the common no-op allocationsSLICEvalues remove their allocation and 288 B/op, with a measured 3.3-4.1% latency increase; the other composite no-op and changed cases improve or are statistically unchangedValuecase and 8.3% faster for the Trace-styleKeyValuecase, while BYTESLICE is statistically unchanged forValueand 2.6% slower forKeyValueBenchmark setup
31d148c597cb29b2eacc1e9c74a62c98a9d140b5plus this PR's benchmark harness only41c3c897d7375a13731e0cd6336a559cd4801e01Raw benchstat output