Repository navigation
[variant] Speed up shredded Variant rebuilds by avoiding redundant work - #1405
XiaoHongbo-Hope wants to merge 8 commits into
Conversation
dfa6543 to
d648ea8
Compare
d648ea8 to
2b06203
Compare
| if metadata.len() > SIZE_LIMIT { | ||
| return data_invalid("Variant value or metadata exceeds constructor size limit"); | ||
| } | ||
| validate_metadata(metadata)?; |
There was a problem hiding this comment.
[P2] Reuse source dictionary validation in compact rebuilds
Selecting a small Variant subtree can preserve its full parent dictionary. For rows fully represented by typed_value, the baseline builds a compact dictionary from the typed fields. This new call validates every key in the source dictionary on a cache miss. Rotating dictionaries that exceed the 1 MiB validation cache make each row repeat the UTF-8 and duplicate-key checks.
I reproduced this with 512 rows of {"age":27}, a shredded age BIGINT field, and no residual value. The rows rotate through nine parent dictionaries, each with 5,362 unused keys, totaling 1.10 MiB of distinct metadata. After an in-memory Parquet round trip, I timed only Arrow reconstruction. The median of 14 debug rebuilds per commit rose from 2.7 ms on the merge base cb8633dc to 785 ms on 2b06203e.
Please reuse successful validation results in a bounded batch-local cache that matches the full metadata bytes.
JingsongLi
left a comment
There was a problem hiding this comment.
The full-value rebuild optimization addresses a real read-path cost. On the merge with current main, 129 Variant tests and 13 Data Evolution integration tests passed. A separate Parquet round-trip reproduced the sparse rebuild regression below.
| if metadata.len() > SIZE_LIMIT { | ||
| return data_invalid("Variant value or metadata exceeds constructor size limit"); | ||
| } | ||
| cache.validate_compact_metadata(metadata)?; |
There was a problem hiding this comment.
[P2] Avoid revalidating the same wide dictionaries on every row
The new cache reuses validation in the nine-dictionary case. With a 512-row Parquet batch rotating through 17 valid dictionaries of 5,363 keys each, it still misses on every row. The dictionaries total 2,096,763 bytes, so this hits the 16-entry limit even though the bytes fit. Each row has only the typed age key and no residual. The baseline compact path rebuilds that value without traversing the unused source keys.
I ran the same in-memory Parquet round-trip on ea90bef2 and its merge with this PR, 89b4caf5. Arrow reconstruction medians were 2.7–2.8 ms on the baseline and 743–750 ms with the PR over two runs of seven samples each, with the same decoded results. Please reuse successful validation across distinct metadata values in a batch, for example by borrowing the metadata bytes from the input Arrow array, and cover a workload above the current entry limit.
| validate_metadata(bytes)?; | ||
| if bytes.len() <= MAX_COMPACT_METADATA_BYTES { | ||
| while self.validated.len() >= MAX_COMPACT_METADATA_ENTRIES | ||
| || self.validated_bytes + bytes.len() > MAX_COMPACT_METADATA_BYTES |
There was a problem hiding this comment.
[P2] Reuse dictionary validation when the working set exceeds 2 MiB
The entry-count change fixes the previous 17-dictionary reproducer. Adding one more dictionary brings the working set to 2,220,102 bytes. With round-robin access, the 2 MiB byte limit evicts each dictionary before its next use, so every row repeats the full UTF-8 and duplicate-key checks.
I reproduced this with 512 rows of {"age":27}, with age fully shredded as BIGINT and no residual. The 18 source dictionaries each contain 5,362 unused keys. I measured Arrow reconstruction after an in-memory Parquet round trip. The median over 14 debug rebuilds per commit was 2.7 ms on the merge base cb8633dc and 789.4 ms on a283a180.
Could we borrow the metadata bytes from the Arrow batch and reuse successful validation for exact byte matches?
| if self.validated_borrowed_addresses.contains(&address) { | ||
| return Ok(()); | ||
| } | ||
| if !self.validated_borrowed.contains(bytes) { |
There was a problem hiding this comment.
[P2] Avoid hashing the full source dictionary on every row
The batch cache now reuses validation beyond the 2 MiB limit. Full Variant reads still decode metadata into a BinaryArray. Each nonempty row has a distinct slice address, so repeated dictionaries reach this content lookup and hash the whole slice. In a CPU sample of the reproducer, about 70% of the Arrow rebuild samples were in slice hashing.
I reran the 512-row Parquet fixture with a fully typed age BIGINT, no residual, and 18 rotating dictionaries of 123,339 bytes each. The median Arrow rebuild time after decoding was 143.6 ms over 14 debug samples on 2279f8d0. Earlier measurements with the same setup were 2.7 ms on the merge base cb8633dc and 789.4 ms on a283a180.
Could full Variant reads reuse the existing Arrow dictionary metadata path and cache successful validation by dictionary key?
JingsongLi
left a comment
There was a problem hiding this comment.
I reviewed 82925b38 and ran the integration checks on GitHub’s merge of that head with main at 5de28de3. All 128 enabled Variant unit tests and 12 integration tests passed, including Variant sidecar reads after column updates and renames, nested schema evolution, and Java/Python ROW interoperability. On an actual local Paimon table the mixed typed/residual scan improved from 3.69 ms to 2.99 ms. The sparse full scans show a regression on the same Parquet files.
| children[metadata] = | ||
| children[metadata] | ||
| .clone() | ||
| .with_data_type(arrow_schema::DataType::Dictionary( |
There was a problem hiding this comment.
[P2] Preserve a fast full-read path when Parquet metadata spills to plain pages
This schema override requests Arrow dictionary output for every shredded metadata child. Arrow can reuse the Parquet keys for dictionary-encoded pages. After a plain page it materializes the bytes and builds a new Arrow dictionary. With a distinct directory of keys per row, the new compact rebuild also validates each source dictionary once even when the row is fully typed and has no residual.
I wrote the fixtures with current main and ran new_scan().plan() through new_read().to_arrow() on the same persisted files with both builds. Output rows matched. For 512 rows of {"age":27} rotating through 18 wide dictionaries, the Parquet footer shows one dictionary-encoded data page and 56 plain data pages. Median full scan time increased from 154.56 ms to 162.68 ms at the top level and from 156.39 ms to 159.99 ms inside a nested ROW. With 512 distinct metadata dictionaries of roughly 9 KiB, one dictionary-encoded data page and four plain data pages, it increased from 14.04 ms to 18.16 ms (29%). These are 11 warm local scans per build with Paimon, Parquet, Arrow Array and Arrow Buffer at opt-level=2.
Please preserve a comparable full-read path for files with plain metadata pages and cover both repeated and distinct dictionaries in the scan benchmark. A dictionary-shaped Arrow output alone can also come from rebuilding a dictionary during the read.
d88b75f to
6d6c51f
Compare
Summary
Validation
cargo test --locked --release -p paimon --no-default-features --features storage-fs,storage-memory --lib variant: 130 passed, 2 ignored.cargo fmt --all --checkandgit diff --checkpassed.These measurements cover local
new_scan().plan()throughto_arrow()materialization, not OSS or training throughput.