fix: bound VortexWriter's global-dict retained memory to avoid OOM on huge files#278
Merged
Conversation
… huge files VortexWriter buffers a global-dict candidate column's raw chunk data in memory from its first chunk until close() -- a shared dictionary can only be built once every chunk has been seen. On a huge, wide file (e.g. an 18.5M-row / 38-string-column real-world Parquet import) any column that looks low-cardinality on an early chunk but never gets demoted keeps its entire column pinned in the heap; with dozens of such columns the total reaches several GB and the import throws OutOfMemoryError, independent of how much heap is available (memory scales with file size x column count, not with a bounded chunk size). Add an aggregate retained-bytes budget (256 MB, GLOBAL_DICT_MAX_RETAINED_BYTES) across all buffering dict-candidate columns. Each chunk appended to a candidate updates a per-column and running-total estimate (estimateRetainedBytes); crossing the budget demotes the largest-retained columns -- flushing their already-buffered chunks as ordinary per-chunk segments and dropping them from future global-dict candidacy -- until back under budget. This bounds writer memory by the budget rather than by total file size, while still giving most columns their shared dictionary in the common case. Regression test (GlobalDictUtf8Test#retainedBytesBudgetExceeded_utf8_demotesToPerChunkChunkedLayout) reproduces the bug shape at small scale via a test-only budget seam (setDictRetainedBudgetForTest): a column with genuinely low, constant cardinality (so the existing cardinality-ratio fallback never fires) whose raw bytes alone cross a lowered budget, forcing mid-file demotion. Asserts the demoted column lands as a plain per-chunk Chunked layout (not Dict) and that every value still round-trips correctly across the demotion boundary. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Jul 18, 2026
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
VortexWriterbuffers a global-dict candidate column's raw chunk data in memory from its first chunk untilclose()— a shared dictionary can only be built once every chunk has been seen.OutOfMemoryError— independent of how much heap is available (memory scales with file size × column count, not with a bounded chunk size).Test plan
GlobalDictUtf8Test#retainedBytesBudgetExceeded_utf8_demotesToPerChunkChunkedLayoutreproduces the bug shape at small scale via a test-only budget seam, asserts the demoted column lands as a plain Chunked layout (not Dict) and that data round-trips correctly across the demotion../mvnw test -pl writer -am— 1705 tests, 0 failures🤖 Generated with Claude Code