Skip to content

perf: avoid formatter allocations in YCSB hash keys - #285

Open
perfloop[bot] wants to merge 1 commit into
mainfrom
perfloop-pr-open-a49qgfwghk
Open

perfloop[bot] wants to merge 1 commit into
mainfrom
perfloop-pr-open-a49qgfwghk

Conversation

@perfloop

@perfloop perfloop Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

hashKey runs before YCSB worker operations and while preloading keys. It keeps the eight-byte FNV-1a sweep and replaces fmt.Sprintf with a 20-byte stack buffer and strconv.AppendUint. The returned key stays user-prefixed, lowercase, and unpadded. The formatter-equivalence test covers zero, positive, negative, and signed int boundaries.

The direct hash benchmark reports per-call time and bytes. A fixed 100,000-call batch gates at least 100,000 fewer allocation events, one for each hash call. A separate RunYCSBWithContext workload runs 100,000 read-only operations with eight workers, 1,000 keys, and 100-byte values against an in-memory loopback gRPC server. Its full-run allocation result is a sampled Go alloc_space estimate attributed to hashKey, including preload; it is not total process allocation or production traffic. Worker-time and throughput are guards, not speedup claims; Result.Duration includes worker hashes but excludes preload and final reporting. The direct-hash and large-run profile harnesses are retained measurement support and are not included in this PR.

On workload YCSB hashKey for 100,000 nonnegative key numbers per sample, median metric hashkey_allocs_per_100000_calls changed from 200009 to 100000; paired median delta -100008 (-50% of baseline; at least 19/20 confidence interval -100010 to -100007 from 10 pairs).

Workload Measure Metric Before median After median Paired change
YCSB hashKey for 100,000 nonnegative key numbers per sample time ns/op 115.2 ns 48.13 ns -58.5%
YCSB hashKey for 100,000 nonnegative key numbers per sample allocated bytes B/op 32 B 24 B -25%
YCSB hashKey for 100,000 nonnegative key numbers per sample hashkey_allocs_per_100000_calls 200009 100000 -50%
YCSB Workload C read-only, 100,000 operations, 8 workers, 1,000 keys, 100-byte values, loopback gRPC hashkey_alloc_bytes_per_ycsb_run 3356450 2451285 -28.4%

Each workload ran 10 paired runs.

The existing BenchmarkRunYCSBReadOnly/64KiB is an additional allocation guard; each Go benchmark iteration is one 64-operation read-only RunYCSBWithContext invocation with four workers, one key, and 64KiB values. Three one-second diagnostic samples reported allocs/op of 24,902 / 24,805 / 24,818 before the change and 24,747 / 24,757 / 24,809 after it. These diagnostic runs are separate from the official paired claim results. No new benchmark or build target is added to the PR.

YCSB Workload C, 64 operations, 4 workers, 1 key, 64KiB values, loopback gRPC (10 paired runs): declared guards passed.

make test-client, make build-cli, make fmt-check, make license-check, and client go vet ./... pass. The full repository make lint remains for target CI.


Generated by Perfloop.


Note

Low Risk
Behavior-preserving hot-path optimization with an equivalence test; key format and hashing logic are unchanged.

Overview
Optimizes YCSB hashKey so preload and every worker op spend less time and heap on key strings. The FNV-1a hash is unchanged; only string assembly moves from fmt.Sprintf("user%x", h) to a fixed user prefix on a 20-byte stack buffer plus strconv.AppendUint (lowercase, unpadded hex).

Adds TestHashKeyMatchesFormatter, which compares the new path to the old formatter for zero, typical values, and signed int min/max so key names stay compatible with existing caches and tests.

Reviewed by Cursor Bugbot for commit 133bd25. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Low impact] The PR appears safe to merge; key names and caller behavior stay unchanged.

Summary

hashKey replaces fmt.Sprintf with strconv.AppendUint and a local 20-byte buffer.

  • YCSB builds hash keys without formatter allocations.

Reviews (1) · Last reviewed commit: "perf: avoid formatter allocations in YCS..." · Reviewed by Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant