Pre-merge immutable tag sources to reduce span creation overhead#11118
Closed
Pre-merge immutable tag sources to reduce span creation overhead#11118
Conversation
…creation buildSpanContext() called setAllTags() 5 times per span, with two of those sources (mergedTracerTags, localRootSpanTags) being immutable across all spans. Every span redundantly re-merged them plus ran a per-span removeTag(Tags.VERSION). This change pre-merges those frozen tag sources into a preMergedRootSpanBase template at ConfigSnapshot creation time and initializes each span's TagMap via copy from the template. Root spans go from 5 setAllTags + removeTag to 3 setAllTags; child spans go from 2 effective setAllTags to 1. tag: no release note tag: ai generated Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
After running a before / after comparison, this change yields negligible real gains. |
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.
Summary
mergedTracerTags + localRootSpanTagsinto a frozenpreMergedRootSpanBasetemplate atConfigSnapshotcreation time (once at init / remote config update, not per-span)TagMapviatagBase.copy()from the template instead ofTagMap.create()+ 5 separatesetAllTags()callssetAllTags+removeTag(VERSION)reduced to 3setAllTagssetAllTagsreduced to 1Tags.VERSIONat merge time instead of per-spanTagMergeBenchmarkJMH benchmarkMotivation:
CoreTracer.buildSpanContext()consumed ~7% of foreground CPU in a 16-thread span creation stress test (6% in buildSpanContext itself + 1% inBucketGroup._cloneEntries). Two of the fivesetAllTags()calls used frozen/immutable tag maps that never change between spans — redundantly re-merged on every span.Benchmark results (8 threads, throughput)
TagMergeBenchmark:
CoreTracerBenchmark (end-to-end):
Test plan
*CoreTracer*tests pass (52/52)*DDSpanContext*tests pass*DDSpan*,*SpanTag*,*TagInterceptor*,*DynamicConfig*tests pass🤖 Generated with Claude Code