[Test] Measure benefits of StringIndex replacement for Lettuce - #12281
[Test] Measure benefits of StringIndex replacement for Lettuce#12281amarziali wants to merge 1 commit into
Conversation
|
🎯 Code Coverage (details) 🔗 Commit SHA: 0c574de | Docs | View more details | Give us feedback! |
🟢 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. |
2787c09 to
ef6f28b
Compare
ef6f28b to
0c574de
Compare
| @Fork(3) | ||
| @Warmup(iterations = 2, time = 2, timeUnit = TimeUnit.SECONDS) | ||
| @Measurement(iterations = 3, time = 2, timeUnit = TimeUnit.SECONDS) | ||
| @Threads(1) |
There was a problem hiding this comment.
Typically, we should use a larger number of threads. That will simulate a server workload more realistic and show the throughput impact of allocation.
Admittedly, allocation isn't a big concern here, but it is still a good habit for dd-trace-java benchmarks.
| new String[] {"CLIENT", "CLUSTER", "COMMAND", "CONFIG", "DEBUG", "SCRIPT"}; | ||
|
|
||
| // --- candidate 1: HashSet, as production declares it today --- | ||
| static final Set<String> NI_HASH_SET = new HashSet<>(Arrays.asList(NON_INSTRUMENTING_WORDS)); |
There was a problem hiding this comment.
To realistically benchmark HashSet / HashMap, we need to first pre-populate the type profile of HashSet. Right now, HashSet will use monomorphic caller specialization in way that isn't realistic for a production load.
I thought I'd done that in the ImmutableSetBenchmark, but apparently not. I think we should actually just update the ImmutableSetBenchmark, since it is doing the same thing as the benchmark but for more set-like set-ups.
| keys(CommandType.GET, CommandType.SET, CommandType.HGETALL, CommandType.INCR); | ||
|
|
||
| /** Administrative commands, present in one or both sets. */ | ||
| static final String[] HIT_KEYS = |
There was a problem hiding this comment.
I think it is okay, but typically, we want to be careful about using string literals for lookups in a benchmark. If we aren't careful, the JIT can perform a branch speculation on a reference equals check which skips compiling the equals check entirely.
In this case, I suspect that using string-literals / string-constants is the norm, so it is fine, but just something to be aware of.
|
closing as superseeded by #12288 |
What Does This Do
Evaluates
StringIndexas replacement forHashSeton Lettuce helper to make command classification faster. Three structures compared:hashSet— what ships todaystringIndexInstance—static final StringIndexviaStringIndex.of(...)stringIndexEmbedded—StringIndex.EmbeddingSupport.indexOfoverstatic final int[]/String[]Two new measurement classes in
lettuce-5.0: a JMH benchmark (speed + allocation) and a JOL test (footprint). Each benchmark arm does both lookups, matching one Redis command._missarms use ordinary commands (GET,SET,HGETALL,INCR), which are in neither set;_hitarms use the administrative commands the sets contain.Results
Speed — ns per command, JDK 17.0.18 / Apple M4 Max,
@Fork(3),@Threads(1):hashSet_perCommand_missstringIndexEmbedded_perCommand_missstringIndexInstance_perCommand_misshashSet_perCommand_hitstringIndexEmbedded_perCommand_hitstringIndexInstance_perCommand_hitAll values ns/op,
avgtmode, Cnt 9 (3 forks × 3 iterations). Lower is better.Miss-path means over six runs:
hashSet1.719,stringIndexEmbedded1.737,stringIndexInstance2.685.Footprint — retained bytes, both sets measured as one graph:
hashSet1056,stringIndexInstance736,stringIndexEmbedded688.Allocation —
gc.alloc.rate.normat the 10⁻⁶ B/op floor for every arm.Conclusions
EmbeddingSupportis a tie, not a win. Means within 1% over six runs, marginally slower on balance, error bars overlapping every time. Not distinguishable from zero.Motivation
Additional Notes
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issueJira ticket: [PROJ-IDENT]