Removing thread contention from Unsynchronized Map Benchmarks#11679
Open
dougqh wants to merge 7 commits into
Open
Removing thread contention from Unsynchronized Map Benchmarks#11679dougqh wants to merge 7 commits into
dougqh wants to merge 7 commits into
Conversation
Throughput microbenchmark for TagMap insert/getObject/getEntry over a representative HTTP-server tag set. All mutable state (the read map) lives in @State(Scope.Thread) so @threads(8) runs measure TagMap rather than cross-thread contention on a shared map/counter/flyweight — the flaw that made earlier TagMap benchmarks misleading. Run config is baked into annotations (the me.champeau.jmh plugin ignores -Pjmh.* flags). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Contributor
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
dougqh
commented
Jun 22, 2026
| public class TagMapAccessBenchmark { | ||
| // a representative HTTP-server-ish tag set (immutable -> safe to share across threads) | ||
| static final String[] NAMES = { | ||
| "http.request.method", |
Contributor
Author
There was a problem hiding this comment.
Future intended changes will care about the specifics of the tags, so using real tags is preferable for future-proofing
sharedLookupIndex was a plain static int incremented by all 8 JMH threads without synchronization — a data race that turned the get benchmarks into a contention measurement rather than a map measurement. Move the index to @State(Scope.Thread) so each thread has its own cursor, matching the approach used in TagMapAccessBenchmark. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Without this, -Pjmh.includes is silently ignored by the me.champeau.jmh plugin, requiring a full fat-jar build to run a single benchmark. -PtestJvm was also ignored for JMH execution, defaulting to the Gradle daemon JVM regardless of the requested version. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Re-run after fixing the shared-index data race, on Java 17 with correct per-thread scaffolding state. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The '2x faster construction' claim was stale — Java 17 numbers show ~40%. Also clarifies that LinkedHashMap's cost is purely at construction; gets and iteration are equivalent to HashMap. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…sBenchmark Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
What This Does
Adds a throughput microbenchmark for the core
TagMapaccess paths —insert,getObject(raw value),getEntry— over a representative HTTP-server-ish tag set.Motivation
Before making further changes to TagMap, I want a more robust benchmark in place. The shared counter used in the benchmark previously was masking some of the differences as compared to other Maps.
Additional Notes
Runs at
@Threads(8). All shared state is immutable (NAMES/VALUES); every bit of mutable state (the pre-populated read map) lives in a@State(Scope.Thread)holder, so threads never contend on a shared map, index, or reader flyweight. Earlier TagMap benchmarks shared a cross-thread counter/index, which turned the result into a contention measurement rather than a TagMap measurement — this layout avoids that. Indices are plain per-invocation locals.Run config is baked into annotations (
@Fork/@Warmup/@Measurement/@Threads) rather than relying on-Pjmh.*flags, which theme.champeau.jmhplugin ignores.Notes
LegacyTagMapremoval (Remove LegacyTagMap; OptimizedTagMap is the sole TagMap implementation #11678) — uses only the publicTagMapAPI, so it builds/runs on master and on that branch alike.DDSpanbenchmark follows once its tracer setup is quieted (a no-op writer to stop per-op DEBUG logging from contaminating throughput).🤖 Generated with Claude Code