Repository navigation
feat: experimental bitBucketSize 'auto' (counts widen 8 -> 16 -> 32 -> 64 on demand) - #78
Draft
alexvictoor wants to merge 1 commit into
Draft
alexvictoor wants to merge 1 commit into
alexvictoor wants to merge 1 commit into
Conversation
…> 64 on demand) AutoCountsHistogram starts with 8-bit counts and copies them into the next wider typed array the first time a count does not fit, instead of throwing (the fixed-width behaviour from the count overflow fix). It is JS only; build() refuses 'auto' with useWebAssembly. The range check run before an auto-resize is a protected hook so the auto histogram promotes there too, and only refuses negative or unsafe counts. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Summary
Stacked on #77 (fixed-width histograms throw on count overflow). Retarget to
masteronce #77 merges.New opt-in
bitBucketSize: "auto"for JS histograms: counts start at 8 bits and widen when a count does not fit, instead of throwing.clearCountsandsubtractkeep the current width.bitBucketSize, including"auto".useWebAssembly: truewith"auto"throwsnot supported with WebAssembly.Evidence
After:
src/AutoCountsHistogram.spec.tsandsrc/AutoCountsHistogram.fc.spec.ts: promotion at 256, 65536 and 2^32 without wrapping, a direct jump to the needed width, counts preserved across promotions, same counts, total, extremes and percentiles as a Float64 twin under random record/add/subtract sequences (fast-check), add/subtract/clear/copy-with-CO-correction, encoding round trips into 8/16/32/64/packed/auto.recordValueWithCount(123456, 300)on an auto-resizing auto histogram threw300 would overflow 8-bit integer count, because fix: 8/16/32-bit histograms throw on count overflow instead of wrapping #77's pre-resize check used the initial 8-bit limit.After: it promotes to 16 bits and records 300. A negative count still throws before the resize.
Speed,
src/bench/counts-promotion.bench.ts, one variant per process (COUNTS_BENCH_ONLY), ops/s, three runs:A fresh histogram is faster because its counts array is 4x smaller. A long-lived one is slower once promoted: the likely cause is that the counts load and store in
incrementCountAtIndexhave seen three typed array kinds, so V8 compiles them polymorphic (not confirmed with a V8 trace). One width-specific function per kind, installed on the instance, was tried and was slower (180k), probably because the call is no longer inlined.Merge Danger
Door: two-way
Opt-in only: no existing
bitBucketSizechanges behaviour. Removing"auto"later would be a breaking change for anyone who adopted it, so it is marked experimental.Blast Radius: contained
TypedArrayHistogramgets a protectedcheckRecordedCounthook and aprotected arrayCtr; the fixed-width classes behave as in #77.BitBucketSizegains"auto", which TypeScript users switching exhaustively over it will notice.🤖 Generated with Claude Code