perf(hotblocks): prepare unspilled chunks in memory#98
Merged
Conversation
mo4islona
force-pushed
the
perf/hotblocks-in-memory-prepare
branch
3 times, most recently
from
July 16, 2026 16:16
3c09eb7 to
d9dc7c3
Compare
Every head flush built a full out-of-core ChunkProcessor — hundreds of temp files created and torn down per block, ~52 ms of mostly kernel time on production hardware, times one flush per block per dataset. When no spill happened and the builder is within the 30 MiB spill bound, finish() now sorts and downcasts straight from the builder into a TableReader::Mem-backed PreparedTable: 0.22 ms, no temp files. Spilled or oversized chunks keep the disk path unchanged. Differential tests pin observational equality with the spill path; ADR 0001 records the investigation. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
mo4islona
force-pushed
the
perf/hotblocks-in-memory-prepare
branch
from
July 16, 2026 16:24
d9dc7c3 to
250a9db
Compare
mo4islona
marked this pull request as ready for review
July 16, 2026 16:25
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.
Problem
At chain head every flush (= every block on 1s chains) builds a full out-of-core
ChunkProcessor: 488 temp files for one EVM block (solana: 229), then tears them down. Measured on the prod node (a production fleet node): ~52 ms per head flush, ~90% kernel time, create+teardown alone = 86%. Fleet-wide that is ~10 CPU cores of syscall/inode churn, growing linearly with dataset count. Full investigation record:docs/adr/0001-in-memory-chunk-prepare.md+docs/measurements/(in this PR).Fix
DataBuilder::finishtakes an in-memory prepared path whenprocessor.is_none()— which by construction (maybe_flushtrims the builder after every block) means the whole chunk still sits in the builder, under the 30 MiB spill bound.prepare_in_memory()sorts and downcasts straight from the builder slices into a newTableReader::Memvariant. No temp files, no syscalls.Chunks that DID spill (backfill, fat bursts) keep the disk path bit-for-bit unchanged — that is the out-of-core design's home turf.
Numbers — measured on the prod node (production fleet node, overlay /tmp, image e96c877)
crates/data/benches/flush_spillinterleaves the three modes and asserts identical record batches on every measured iteration:Cross-mode output equality held for the whole sweep, both on overlay /tmp and tmpfs.
Safety
crates/data-core/tests/in_memory_prepare.rs): byte-equality with the spill path — sorted + plain tables, strings, lists, nulls, empty tables, partial read windows, chunk-wide downcast consistency (incl. >u32::MAX block numbers).finish()re-checks the existing 30 MiB spill bound, so an oversized unspilled chunk (a row-bound flush whose final block is fat) falls back to the disk path. Pinned by unit tests on both sides of the bound.into_processor()on a mem-prepared table errors explicitly — processor reuse is a separate, riskier fix (see the ADR, Alternatives).Rollout
testnet-dev → mainnet-internal (canary) → mainnet/morpho, judged by same-pod before/after per-thread profile (same-pod before/after per-thread profile). Rollback = image tag revert.
Before undrafting
flush_spillon a production fleet node with thememmode (imagee96c877) — 52.4 → 0.224 ms, −99.6%crates/hotblocks/tests/peak_rss.rscompute_order), and byte-equality on ties currently holds anyway (pdqsort sorted-run identity, pinned by test; multiset test is the semantic floor)🤖 Generated with Claude Code