-
Notifications
You must be signed in to change notification settings - Fork 355
Store known span tags densely in TagMap by tag-id (phase 2) #12045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
dougqh
wants to merge
1
commit into
master
Choose a base branch
from
dougqh/dense-store-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
150 changes: 150 additions & 0 deletions
150
internal-api/src/jmh/java/datadog/trace/api/DenseStoreAllocBenchmark.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| package datadog.trace.api; | ||
|
|
||
| import datadog.trace.bootstrap.instrumentation.api.Tags; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Fork; | ||
| import org.openjdk.jmh.annotations.Level; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.annotations.Param; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.Threads; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
| import org.openjdk.jmh.infra.Blackhole; | ||
|
|
||
| /** | ||
| * Deterministic allocation A/B for the dense known-tag store, using the REAL {@link KnownTags} | ||
| * resolver (a {@code StringIndex} probe + a constant-returning {@code switch} — allocation-free, | ||
| * exactly like production). An earlier synthetic prefix resolver allocated in {@code keyOf} | ||
| * (substring) and {@code nameOf} (concat), contaminating the dense arm; this measures the store, | ||
| * not the resolver. | ||
| * | ||
| * <p>Models how a real span's tags route: {@code today} = all custom (what ships now — every tag | ||
| * buckets, since nothing is registered as known), {@code dense} = the same tag count with a | ||
| * realistic fraction routed to the dense store (real known tag names) and the rest custom. Run with | ||
| * {@code -prof gc}; the {@code gc.alloc.rate.norm} (B/op) delta at the same {@code tagCount} is | ||
| * what enabling the dense store does to a real span's per-build allocation. | ||
| * | ||
| * <p><b>Results — buildMap, JDK 17 (Zulu 17.0.7, Apple Silicon), {@code -prof gc -f 1 -wi 2 -i 3}, | ||
| * 2026-07-08.</b> Allocation is deterministic (±0.001 B/op); throughput on this run is NOT | ||
| * trustworthy (single fork, short) — read B/op only. | ||
| * | ||
| * <pre>{@code | ||
| * scenario tagCount=7 tagCount=12 | ||
| * today 408 B/op 704 B/op | ||
| * dense 376 B/op 416 B/op | ||
| * allKnown 176 B/op 400 B/op | ||
| * }</pre> | ||
| * | ||
| * <p>Gate met: {@code dense < today} at both counts (the over-provision artifact is gone). The | ||
| * Entry-less win scales with the known-tag fraction — ~8% at 7 tags (~70% known), ~41% at 12; | ||
| * {@code allKnown} (the codegen endgame / read-through parent shape) reaches ~57% at 7. | ||
| * | ||
| * <p><b>Serialize paths (same run, B/op).</b> {@code buildAndSerialize} (alloc-free {@code forEach} | ||
| * flyweight) adds a flat +16 B/op over {@code buildMap} in every scenario (7: 392, 12: 432 dense). | ||
| * {@code buildAndSerializeViaIterator} — the {@code EntryReader} enhanced-for modeling the count | ||
| * pre-pass at {@code TraceMapperV0_4:95} — adds a CONSTANT per-call cost (+56 custom / +80 dense, | ||
| * identical at 7 and 12 tags): that flat-vs-tagCount signature is the {@code EntryReaderIterator} | ||
| * OBJECT, NOT per-tag Entry — the iterator reuses a dense flyweight (TagMap:2182/2652). So the | ||
| * dense win SURVIVES serialization; the only nit is {@code iterator()} allocating one Iterator per | ||
| * call, which {@code forEach} avoids and which can be recycled away. | ||
| */ | ||
| @State(Scope.Benchmark) | ||
| @BenchmarkMode(Mode.Throughput) | ||
| @OutputTimeUnit(TimeUnit.SECONDS) | ||
| @Warmup(iterations = 2, time = 2) | ||
| @Measurement(iterations = 3, time = 2) | ||
| @Fork( | ||
| value = 1, | ||
| jvmArgsAppend = {"-Ddd.trace.experimental.dense.tags.enabled=true"}) | ||
| @Threads(1) | ||
| public class DenseStoreAllocBenchmark { | ||
|
|
||
| // Real stored (dense-routed) tag names — a realistic web/db span's known set. | ||
| static final String[] KNOWN = | ||
| new String[] { | ||
| DDTags.BASE_SERVICE, | ||
| Tags.VERSION, | ||
| Tags.COMPONENT, | ||
| Tags.SPAN_KIND, | ||
| Tags.HTTP_METHOD, | ||
| Tags.HTTP_ROUTE, | ||
| Tags.DB_TYPE, | ||
| Tags.DB_INSTANCE, | ||
| Tags.PEER_HOSTNAME, | ||
| Tags.DB_USER, | ||
| DDTags.LANGUAGE_TAG_KEY, | ||
| Tags.PEER_PORT, | ||
| }; | ||
|
|
||
| // today = all custom (all bucket, what ships now); dense = ~70% known + custom (a real span); | ||
| // allKnown = 100% known (the trace-tier read-through parent's shape — exercises lazy buckets). | ||
| @Param({"today", "dense", "allKnown"}) | ||
| String scenario; | ||
|
|
||
| @Param({"7", "12"}) | ||
| int tagCount; | ||
|
|
||
| private String[] keys; | ||
| private String[] values; | ||
|
|
||
| @Setup(Level.Trial) | ||
| public void setup() { | ||
| KnownTags.init(); // registers the real (allocation-free) resolver | ||
| int knownCount; | ||
| if ("allKnown".equals(scenario)) { | ||
| knownCount = tagCount; // 100% known (<= KNOWN.length) | ||
| } else if ("dense".equals(scenario)) { | ||
| knownCount = (tagCount * 7) / 10; // ~70% known + custom | ||
| } else { | ||
| knownCount = 0; // today: all custom (all bucket) | ||
| } | ||
| this.keys = new String[tagCount]; | ||
| this.values = new String[tagCount]; | ||
| for (int i = 0; i < tagCount; i++) { | ||
| this.keys[i] = i < knownCount ? KNOWN[i] : "custom.tag." + i; | ||
| this.values[i] = "value-" + i; | ||
| } | ||
| } | ||
|
|
||
| @Benchmark | ||
| public TagMap buildMap() { | ||
| TagMap m = TagMap.create(16); | ||
| for (int i = 0; i < tagCount; i++) { | ||
| m.set(keys[i], values[i]); | ||
| } | ||
| return m; | ||
| } | ||
|
|
||
| @Benchmark | ||
| public void buildAndSerialize(Blackhole bh) { | ||
| TagMap m = TagMap.create(16); | ||
| for (int i = 0; i < tagCount; i++) { | ||
| m.set(keys[i], values[i]); | ||
| } | ||
| // forEach: the alloc-free flyweight emit for dense | ||
| m.forEach(reader -> bh.consume(reader.objectValue())); | ||
| bh.consume(m); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public void buildAndSerializeViaIterator(Blackhole bh) { | ||
| TagMap m = TagMap.create(16); | ||
| for (int i = 0; i < tagCount; i++) { | ||
| m.set(keys[i], values[i]); | ||
| } | ||
| // models the REAL serializer's count pre-pass (TraceMapperV0_4:95). The EntryReader iterator | ||
| // uses a reused dense flyweight (NO per-tag Entry alloc — TagMap:2182/2652), so the dense win | ||
| // SURVIVES; the only extra cost vs forEach is the EntryReaderIterator object itself (a fixed | ||
| // per-call cost, constant across tagCount — not per-tag). forEach avoids even that. | ||
| for (TagMap.EntryReader reader : m) { | ||
| bh.consume(reader.objectValue()); | ||
| } | ||
| bh.consume(m); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new configuration is stored and exposed through a getter but is omitted from
Config.toString(), contrary to the repository's configuration checklist. As a result, startup diagnostics and tracer-flare configuration dumps cannot show whether this experimental storage mode was requested, making failures specific to dense routing substantially harder to identify; addtraceDenseTagsEnabledto the serialized configuration state.AGENTS.md reference: AGENTS.md:L37-L43
Useful? React with 👍 / 👎.