Skip to content

perf(index): benchmark zone map write seeds across data types - #9792

Closed
LuQQiu wants to merge 1 commit into
lance-format:mainfrom
LuQQiu:lu/ent2893-zonemap-seed-bench
Closed

LuQQiu wants to merge 1 commit into
lance-format:mainfrom
LuQQiu:lu/ent2893-zonemap-seed-bench

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What question does this PR answer?

How much does collecting ZoneMap statistics during an append slow down writing, and how much work does it save when we later update the index?

A ZoneMap summarizes groups of rows with min/max and null information. Write seeds store these summaries in the new data files while those files are being written. A later index update can read the summaries instead of reading the column again.

Seeds OFF:
Append data
    → later read the new column values and calculate statistics
    → write the updated ZoneMap index

Seeds ON:
Append data and collect statistics into seeds
    → later read those seeds
    → write the updated ZoneMap index

This PR measures both sides of that tradeoff. It changes no defaults.

What is tested?

The benchmark runs three separate measurements:

Test What happens inside the timed region? What does it measure?
Seed collection (micro) Feed batches to ZoneMapSeedWriter, then serialize seeds at each data-file boundary. The direct cost of collecting and storing statistics, without writing the data files.
Append (e2e) Append identical data to an indexed table, once with seeds disabled and once with seeds enabled. The change in real append time, CPU usage, and peak resident memory. Table creation and initial index creation are outside the timed region.
Later index update (benefit) Reopen the appended dataset with a fresh session and call optimize_indices(). Total incremental update time, including reading values or seeds, processing statistics, and writing the updated index. Initial index creation is not included.

The cases cover numeric types, Boolean, decimals, strings, binary values, nested types, different null distributions, different zone sizes, and tables with 16 or 64 indexed columns.

Both modes receive identical input for each repetition. Each measurement runs in a fresh child process. The benchmark records read requests and bytes during the index update, and tracing events confirm whether it harvested seeds or fell back to scanning.

How to read the results

Result column Meaning
Column / input The data type and distribution being tested. Rows containing several cases list their results in the same order.
Extra append time with seeds Percentage increase in elapsed append time relative to seeds OFF: (on / off - 1) × 100%. For example, +22% means the append takes 1.22 times as long; it is not a 22% reduction in throughput.
Seed bytes per 1M rows Serialized seed-buffer size, normalized to 1M rows. Includes zone summaries and the row-level null-position bitmap. This is not the complete ZoneMap index size or its in-memory cache size. For wide-table cases, it is the total across all columns.
Later index update without seeds Total elapsed time of optimize_indices() after the append, reading the new column values, computing statistics, and writing the updated index. Covers the whole appended batch.
Later index update with seeds Total elapsed time of optimize_indices() after the append, reading the saved seeds and writing the updated index. Covers the same appended batch as the without-seeds measurement.
Min/max available? Whether the measured implementation produces min/max for this type. No means seeds still provide null information, but cannot provide value-range bounds. All-null zones have no non-null bounds even for a supported type.

Row counts: most cases append 4M rows; cases with values of at least 2 KiB append 1M rows. Seed sizes are always normalized to 1M rows. The two timing columns should be compared within each case, not across different row counts.

Results

Medians of five repetitions:

Column / input Extra append time with seeds Seed bytes per 1M rows Later index update without seeds Later index update with seeds Min/max available?
Int32, Int64, Float64, Date32, Timestamp +17% to +22% (about +2.4 ms per 1M rows) 5–6 KiB 34–42 ms 4–5 ms Yes
Boolean +135% (16 ms → 38 ms) 4 KiB 42 ms 5 ms Yes
Decimal128(38,10) +11% 8 KiB 54 ms 4 ms Yes
FixedSizeBinary: 16 B / 4096 B +4% / within noise 8 KiB / 988 KiB 48 ms / 509 ms 4 ms / 5 ms No
Utf8: 32-character hex IDs +5% 12 KiB 152 ms 5 ms Yes
Utf8: 100 distinct values / user_<n> +17% / +8% 6–8 KiB 78 ms / 90 ms 5 ms / 5 ms Yes
Utf8: approximately 256 B / 2 KiB / 8 KiB +1.5% / +0.3% / +0.1% 53 KiB / 403 KiB / 1.6 MiB 360 ms / 241 ms / 672 ms 9 ms / 11 ms / 15 ms Yes
Utf8: approximately 2 KiB, sorted +0.4% 403 KiB 236 ms 10 ms Yes
Binary: 64–256 B +7.5% 43 KiB 239 ms 6 ms Yes
LargeBinary: 20 KiB, random / sorted Within noise 4.8 MiB Approximately 6.5 s Approximately 16 ms Yes
FixedSizeList: 768 Float32 values per row +206% (1.5 s → 4.7 s for 1M rows) 765 KiB 3.6 s 5 ms No
List +2,600% (0.21 s → 5.7 s for 4M rows) 5 KiB 5.5 s 6 ms No
Struct<i32, utf8> +1% 6 KiB 104 ms 6 ms No
Int64: 1% / 10% / 50% / 100% random nulls +18% / +44% / +48% / +142% 68 / 499 / 518 / 518 KiB 64 ms / 77 ms / 117 ms / 81 ms 5 ms / 8 ms / 9 ms / 9 ms Yes, when non-null values exist
Int64: 50% clustered nulls +26% 262 KiB 71 ms 7 ms Yes, when non-null values exist
Utf8: approximately 2 KiB, 50% random nulls +0.4% 916 KiB 205 ms 10 ms Yes, when non-null values exist
Utf8 hex IDs: 1024 / 65536 rows per zone +7% / +4% 86 / 3 KiB 162 ms / 138 ms 12 ms / 5 ms Yes
Mixed table: 16 / 64 columns, ZoneMap on each +3.3% / +14% 259 KiB / 1.1 MiB, all columns combined 1.27 s / 4.7 s 61 ms / 0.46 s Yes

Unless specified otherwise, zones contain 8192 rows. Peak RSS during append did not differ measurably between modes. CPU usage increased by 2.7% for the 16-column table and 4.5% for the 64-column table.

What do these results tell us?

  • Narrow numeric columns: collecting seeds adds a few milliseconds per million rows. That is noticeable relative to a fast local append, but avoids a later column scan. The measured update reads about 40 KB with seeds instead of 16–32 MB of column data for 4M rows.
  • Large strings and binary values: seed collection adds little relative write cost, while avoiding expensive later reads. At 8192 rows per zone, stored extrema are about 0.025% of the uncompressed value bytes; file encoding and compression affect the ratio to actual data-file size.
  • Lists and vectors: the current path computes statistics for list contents that ZoneMap subsequently discards. Only null information survives. This explains the large write overhead and warrants a follow-up before broad default enablement.
  • FixedSizeBinary: the current statistics implementation produces no min/max. Faster index updates therefore do not establish useful value-range pruning for this type.
  • Nulls: seeds record individual null positions in a Roaring bitmap, hex-encoded in IPC metadata. This adds substantially more work and storage than a null count alone. For example, Int64 seeds grow from roughly 6 KiB without nulls to 499 KiB with 10% scattered nulls per 1M rows. The all-null seed is comparable to the measured encoded data-file size, not to 8 MB of uncompressed Int64 values.
  • Wide tables: costs accumulate across columns. The 64-column append takes 14% longer in this measurement.

These measurements inform follow-up decisions about supported types, default enablement, and seed size. Those decisions are not implemented here.

Validation and scope

47 cases, 1165 child runs, zero reported failures. Seed harvesting was confirmed in all five repetitions of every seeds-on case; seeds-off updates reported plugin_declined fallback. Validation passed for every case.

The benchmark compares seed-built and scan-built statistics zone by zone, including float validity and bit patterns, and compares query row-ID multisets with indexes enabled and disabled. A regression test specifically covers partial final zones, all-null zones, NaNs, signed zeros, and harvest/fallback events.

This measures the existing path: an indexed column with use_seeds = true, WriteMode::Append, and a supported data-file version. Collecting seeds without an existing ZoneMap index is separate work. The PR does not measure query speed or the full index's resident memory.

Changes included

  • rust/lance/benches/zone_map_seeds.rs: the three-layer benchmark, process isolation, resource measurements, and validation.
  • index/append.rs and tracing constants: index_seeds_harvested and index_seeds_fallback_scan events, including fallback reasons.
  • dataset/write.rs: the seed-versus-scan regression test.
  • docs/src/guide/performance.md: measured write-seed costs and observations.

Environment and reproduction

AMD EPYC 9V65, 368 vCPU, 1.3 TiB RAM, local NVMe RAID 0, Linux 5.15, Rust 1.98.1, release-with-debug, Lance base 518dc4c28 plus this branch. Batches contain 8192 rows; data files target 1M rows. OS page cache was warm; Lance caches were cold. “Within noise” means no clear difference was observed, not zero cost.

cd rust
ROWS=4000000 REPEAT=5 VALIDATE=first OUT=/tmp/zmseed.jsonl DATA_DIR=/mnt/nvme/zmseed \
  cargo bench --profile release-with-debug --bench zone_map_seeds

SCENARIOS= selects cases (--list prints them); LAYERS=micro,e2e,benefit selects measurements.

🤖 Generated with Claude Code

Add a bench that measures what zone map write seeds cost on the append
path and save on the index update path for a matrix of column types and
value distributions, emit tracing events when a scalar index merge
harvests seeds or falls back to a column scan, and test that a
seed-built zone map matches a scan-built one bit for bit.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-docs Documentation performance labels Oct 8, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

The instrumentation preserves the current update behavior, and the validation supports using this benchmark to inform the separate seed-defaults decision.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 8, 2026
@LuQQiu
LuQQiu marked this pull request as draft October 8, 2026 21:42
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 8, 2026
@LuQQiu LuQQiu closed this Oct 10, 2026
@LuQQiu

LuQQiu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Trimmed this PR down to what is worth keeping in the tree:

  • Removed the benchmark (rust/lance/benches/zone_map_seeds.rs and its [[bench]] entry). It answered a one-off question and is not worth maintaining against API churn; it lives on the fork branch lu/ent2893-zonemap-seed-bench-tool, which the docs section now links to for reproduction.
  • Seed events are debug, not info, and there is no event when an index type simply never produces seeds (BTree, Bitmap, …). What remains: index_seeds_harvested when a merge used seeds, and index_seeds_fallback_scan with reason = seed_missing | seed_rejected when an index that expected seeds had to scan. Both on target lance::dataset_events, one event per index merge.
  • Kept the bit-for-bit seed-vs-scan test and the measured matrix in docs/src/guide/performance.md.

Net diff is now ~300 lines instead of ~2,000.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant