goodhistogram: perf-eval of exact min/max tracking on the hot path - #12
Draft
angles-n-daemons wants to merge 3 commits into
Draft
goodhistogram: perf-eval of exact min/max tracking on the hot path#12angles-n-daemons wants to merge 3 commits into
angles-n-daemons wants to merge 3 commits into
Conversation
Add experimental RecordMinMax / RecordMinMaxPadded variants that track the exact minimum and maximum observed value via a load-guarded CAS loop, plus an A/B benchmark across input ordering (steady/ascending/descending) and concurrency (1/50/100 goroutines). Includes arm64 (Apple M3 Pro) results and write-up under reports/. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
Run the same A/B suite on gceworker-briandillmann (24 vCPU x86_64, Go 1.25.5) and add a cross-architecture comparison. x86 shows a clean, consistent ~10% Record overhead for inline min/max (arm64 M3 numbers were noisy under contention). Padding is neutral-to-worse on both arches. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
…f-eval Third architecture: GCE t2a-standard-8 (8 vCPU Ampere Altra, Neoverse N1). Single-thread shows a clean ~+13% Record overhead (consistent with x86's +10%); contention is noisy like the M3. Notably, cache-line padding is a wash here — the "padding hurts" penalty seen on the Apple M3 is M3-specific, not arm64. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.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
Evaluates the cost of tracking the exact minimum and maximum value observed
by a
goodhistogram, added to the lock-freeRecordhot path.Today
Recorduses fetch-and-add for the bucket counters andsum. Exactextremes can't use fetch-and-add — each needs a load-guarded compare-and-swap:
The guard load short-circuits the steady state, so the CAS only fires when an
extreme actually moves. This PR adds experimental
RecordMinMax/RecordMinMaxPaddedvariants plus an A/B benchmark, and writes up the results.It is a measurement branch, not a merge candidate — no change to the default
Record.How it was measured
Three variants A/B'd:
baseline(today'sRecord),minmax(twoatomic.Int64inline next to
sum), andpadded(each extreme on its own cache line, toisolate false sharing). Independent variable is input ordering —
steady(shuffled),
ascending(new max every call),descending(new min every call) —crossed with concurrency (1 / 50 / 100 goroutines),
-count=8, benchstat, onthree machines:
Results — single-threaded (steady, sec/op vs. baseline)
Single-thread variance is ±0–2% on both servers → all deltas significant
(p < 0.001). Ordering (steady/ascending/descending) changes nothing (within ~1%).
Results — high contention (representative, sec/op vs. baseline)
Only the x86 server gives a clean contention signal (~+10%); both arm machines
are too noisy (±5–40%) to distinguish min/max from baseline.
Findings
Recordoverhead across all three machines(+10% x86, +13% Ampere arm, +26% M3 — higher only because the M3 baseline is
~5–8× faster in absolute terms). ~0.7–2 ns/op, zero allocations.
~+10%). The contended
sum.Addalready dominates; read-mostly guard loads addlittle. Treat as "no clear regression."
even for monotonic input. (Caveat: each goroutine replays the same array, so
the shared extreme settles fast; an unbounded global monotonic stream would
contend harder, untested.)
not arm64-general. Padding tanked the M3 under contention (up to +55%) but is
a wash on the Ampere arm server and x86. Co-locating the read-mostly extremes
with the already-hot
sumline (inline) is at least as good everywhere.Recommendation
Exact min/max is cheap enough to ship: ~10–13% single-threaded
Recordoverhead(~0.7–2 ns/op), no clear contention regression, zero allocations — using the
inline load-guarded CAS (skip padding). If that ever matters on an ultra-hot
path, derive approximate extremes from populated bucket edges at
Snapshottimefor zero hot-path cost (trading exactness for bucket-width error).
Full write-up and raw data under
reports/minmax_perf_eval.md.