Commit 4205397
Cache hashCode on UTF8BytesString (#11444)
Cache hashCode on UTF8BytesString
UTF8BytesString.hashCode() currently delegates straight through to
String.hashCode() on every call. String already caches its own hash,
but the trip out of UTF8BytesString and through String's hash-field
check still costs a virtual dispatch + field read + branch on every
invocation.
Caches the hash on UTF8BytesString itself once computed. Benign-race
pattern, identical to the existing utf8Bytes lazy initializer: two
threads computing the same value produce identical results, and int
writes are atomic per JLS so a reader can't observe a partial value.
Measured on the metrics subsystem's adversarial JMH bench (8 producer
threads, high-cardinality unique-per-op labels), this lifts aggregate
throughput from 5.17M to 5.78M ops/s -- ~12% improvement, with the
per-iteration distribution shifting systematically upward across all
five measurement iterations. The win is bigger in production-like
workloads with repeated keys, since the cardinality-handler intern
pool means the same UTF8BytesString instance gets hashed repeatedly
in subsequent reporting cycles.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Merge branch 'master' into dougqh/utf8bytesstring-cache-hashcode
Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>1 parent 970f5ee commit 4205397
1 file changed
Lines changed: 13 additions & 1 deletion
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
61 | 68 | | |
62 | 69 | | |
63 | 70 | | |
| |||
114 | 121 | | |
115 | 122 | | |
116 | 123 | | |
117 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
118 | 130 | | |
119 | 131 | | |
120 | 132 | | |
| |||
0 commit comments