Skip to content

perf: cheaper cascading writes (ALP-RD, string min/max, float stats) - #543

Merged
dfa1 merged 3 commits into
mainfrom
perf/alprd-and-dict-stats
Oct 17, 2026
Merged

dfa1 merged 3 commits into
mainfrom
perf/alprd-and-dict-stats

Conversation

@dfa1

@dfa1 dfa1 commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Summary

Three independent write-path optimizations found by profiling JavaVsJniWriteBenchmark.javaWrite (depth 3) with YourKit async CPU sampling. None changes what is written: the encoder verdicts and bytes stay the same.

  • ALP-RD: count left-bit patterns with LongIntMap instead of a boxed HashMap, scan the (at most 8 entry) dictionary linearly instead of a boxed Map<Short,Short> lookup per row, and keep exceptions in primitive arrays. Selection order is unchanged (most frequent first, ties by ascending unsigned pattern, as Rust's select_dictionary); new F64/F32 tests pin the unsigned tie-break for sign-bit-set patterns.
  • String min/max in the global dictionary: compare each dictionary code once per chunk instead of two UTF-8-order compares per row. The "seen" array grows with the dictionary, not the cap, so low-cardinality columns hold no unaccounted memory.
  • Float stats: count once per run of equal bit patterns, as the integer path already does. Counts are identical to a per-row scan; Rust probes every row, so this changes cost only.

Measurements

javaWrite depth 3, interleaved A/B against main, -f 2, quiet machine:

main this PR
throughput 0.954 ops/s 1.107 ops/s (about +15%, intervals touch)
allocation per op 2.652 GB 2.315 GB (-12.7%, stable to <0.1%)

With -XX:+UseCompactObjectHeaders: 1.032 vs 1.149 ops/s, same 12.7% allocation drop. Per-commit gains are within noise individually; the allocation figure is the solid one.

Review

Reviewed by an Opus subagent (no serious findings). Its two should-fix items are addressed in the commits: the stamp array sizing and the missing unsigned tie-break tests.

Test plan

  • ./mvnw verify (all modules, 2888 integration tests, javadoc)
  • new tests: ALP-RD unsigned tie-break (F64/F32), per-chunk string min/max across shared/unshared codes, float counting paths vs brute force

🤖 Generated with Claude Code

@dfa1
dfa1 force-pushed the perf/alprd-and-dict-stats branch from 48dd607 to 11f6d0f Compare October 16, 2026 21:05
dfa1 and others added 3 commits October 17, 2026 12:05
The dictionary search counted left-bit patterns in a HashMap<Short,Integer> per cut,
the per-row code lookup went through a boxed Map<Short,Short>, and exceptions were
collected in List<Long>/List<Short>. Count with LongIntMap, scan the (at most 8
entry) dictionary linearly, and keep exceptions in primitive arrays.

Selection order is unchanged: most frequent first, ties by ascending unsigned pattern
(Rust's select_dictionary). JavaVsJniWriteBenchmark.javaWrite depth=3, -f 3:
0.878 -> 1.057 ops/s (error intervals overlap, machine noisy).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
DictColumnState.ingestDictChunk already maps every row to a code, but then
VarBinEncodingEncoder.minMaxStats re-scanned all rows with two UTF-8-order
comparisons each (~4.5% of CPU in a cascading write profile). A chunk's extremes
depend only on its distinct values, so compare a code the first time it appears in
the chunk. Per-code stamps avoid clearing a flag array per chunk.

Adds a test pinning per-chunk results across chunks that share and do not share codes,
and the UTF-8 vs UTF-16 order of a supplementary character. Interleaved A/B on
javaWrite depth=3: 0.709 -> 0.751 ops/s, within noise.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
scanF16/F32/F64 probed the hash map for every row, ~10% of CPU in a cascading write
profile. Count a run of equal bit patterns with one probe, as the integer path
already does (#10037/#10041 in Rust for ints). Counts are exactly the per-row ones,
so every encoder verdict is unchanged; Rust probes every row, this changes cost only.
Keys stay raw bits, so NaN and -0.0 remain distinct patterns.

Adds a brute-force reference test over runny and scattered F16/F32/F64 inputs.
Interleaved A/B on javaWrite depth=3: 1.088 -> 1.131 ops/s, within noise.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dfa1
dfa1 force-pushed the perf/alprd-and-dict-stats branch from 11f6d0f to a48e11b Compare October 17, 2026 10:07
@dfa1
dfa1 merged commit 593c4b9 into main Oct 17, 2026
7 checks passed
@dfa1
dfa1 deleted the perf/alprd-and-dict-stats branch October 18, 2026 06:18
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