Overhaul map JMH benchmarks: remove thread contention and split by use case#11679
Open
dougqh wants to merge 11 commits into
Open
Overhaul map JMH benchmarks: remove thread contention and split by use case#11679dougqh wants to merge 11 commits into
dougqh wants to merge 11 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>
Align TagMapAccessBenchmark with UnsynchronizedMapBenchmark at @fork(2) for steadier numbers (results to be refreshed on the next run). Also revert the internal-api/build.gradle.kts -Pjmh.includes / -PtestJvm wiring, which belongs in its dedicated PR (#11703), not here. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…Benchmark Replace UnsynchronizedMapBenchmark with two classes that each pick the correct threading model for their use case (the @State scope can't vary by @Param, so one class can't host both): - ImmutableMapBenchmark: precomputed/read-mostly maps shared across threads (@State(Scope.Benchmark)) -- sharing is correct since read-only. get/iterate across HashMap, LinkedHashMap, TreeMap, TagMap. - SingleThreadedMapBenchmark: per-thread mutable lifecycle (@State(Scope.Thread)). create/clone + reads. Adds a Collections.synchronizedMap case to measure the uncontended synchronization tax (per-thread => bias never revoked); the unsynchronized HashMap get/iterate are the in-harness baseline. The biased- locking effect shows when comparing across JVM versions at stock flags. Also fixes a latent bug in the old iterate_linkedHashMap, which iterated TREE_MAP. Stale result blocks dropped; numbers pending a fresh multi-JVM run. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
dougqh
added a commit
that referenced
this pull request
Jun 23, 2026
…edMapBenchmark StringIndex's benchmark integration is moving to the dedicated benchmark PRs (set overhaul #11721, map overhaul #11679) and will be folded in there later. Revert both benchmark files to master so this PR is purely the StringIndex data structure + tests. Avoids the #11679/#11721 deletions-vs-edits conflicts too. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Add a Map.copyOf case (via CollectionUtils.tryMakeImmutableMap -> JDK MapN) to ImmutableMapBenchmark: get / get_sameKey / iterate. MapN is the agent's actual fixed-config-map representation and the honest immutable-map baseline. - Fix TagMapAccessBenchmark's @link to the deleted UnsynchronizedMapBenchmark -> SingleThreadedMapBenchmark (which now holds the clone cases). - Note that interned (_sameKey) lookups are the common tracer case (keys are typically interned tag-name constants). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bric3
approved these changes
Jun 24, 2026
| tagMap.set(INSERTION_KEYS[i], i); // primitive support | ||
| } | ||
| // JDK compact immutable map (MapN on Java 10+); the agent's actual fixed-map representation. | ||
| copyOfMap = CollectionUtils.tryMakeImmutableMap(hashMap); |
Contributor
There was a problem hiding this comment.
quibble: Maybe there's a better name than copyOf, maybe tracerImmautableMap
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
Overhauls the
internal-apimap microbenchmarks so each one isolates the dimension it actually claims to measure, and splits the general map benchmark by use case.TagMapAccessBenchmark— removes cross-thread contention: all shared state is immutable, while every bit of mutable state (the pre-populated read map, lookup index, reader flyweight) lives in a@State(Scope.Thread)holder, so threads never contend on a shared map. Now runs at@Fork(2)to match the rest.Splits
UnsynchronizedMapBenchmarkinto two classes. The correct JMH@Statescope differs by use case and can't vary by@Param, so one class can't host both threading models:ImmutableMapBenchmark— precomputed / read-mostly maps shared across threads (@State(Scope.Benchmark)); sharing is realistic and contention-free because nothing mutates after construction.get/iterateacrossHashMap,LinkedHashMap,TreeMap,TagMap.SingleThreadedMapBenchmark— per-thread mutable lifecycle (@State(Scope.Thread)):create/clone+ reads. Adds aCollections.synchronizedMapcase to measure the uncontended synchronization tax — each thread owns its synchronized map, so the monitor is only ever locked by one thread (bias never revoked). The unsynchronizedHashMapget/iterateare the in-harness baseline; the tax is the delta.Fixes a latent bug: the old
iterate_linkedHashMapiteratedTREE_MAP.Motivation
Before making further changes to
TagMap, I want robust benchmarks in place. The previous shared mutable state (a cross-thread counter/index, shared maps) turned several "iteration / lookup" benchmarks into contention measurements rather than measurements of the map itself. Isolating state per thread — and separating the read-mostly-shared use case from the single-threaded-mutable one — fixes that.Notes
-Pjmh.includes/-PtestJvmgradle wiring was moved to its dedicated PR (Wire -Pjmh.includes and -PtestJvm into internal-api JMH config #11703); this PR no longer touchesbuild.gradle.kts.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.🤖 Generated with Claude Code