refactor: speed up the Parquet time-series read path #8

Merged
aleksei merged 1 commit from perf/tsdb-parquet-query into main 2026-10-21 11:17:02 +00:00
Owner

Optimize the eve_tsdb_parquet read path. The tsdb query benchmark (10,000 seeded rows, value=gt=5000, sort +date, limit 100) drops from ~8.45 ms to ~4.88 ms without changing the public API, query results or the on-disk format.

Why it was slow

  1. Every Arrow Timestamp(ms) was formatted to an RFC 3339 string for every scanned row.
  2. The sort comparator then parsed those strings back to milliseconds on every comparison (~60k comparisons for 5,000 rows).
  3. raw_page sorted every matching row before applying offset/limit.
  4. Dates were rendered for all 10,000 rows even though only the 100-row page is returned.

Changes

  • Internal date form is UTC milliseconds. table::DateMode::{Millis, Rfc3339} selects the representation; all internal reads (query, purge, export, compaction) use Millis, while store::decode_part keeps Rfc3339 for the public ParquetCodec contract. TableSchema::render_row converts only the returned page back to the canonical string. rows_to_batch already accepts a numeric millisecond date, so purge/export/import/compaction are unchanged on disk.
  • Stable top-k pagination. filter::sort_and_paginate uses select_nth_unstable_by for the first offset + limit rows and sorts only that prefix when the page does not cover the whole result; the original row index is the final tie-break, so equal keys keep the old stable order. No limit still uses a full sort.
  • Regex on dates stays correct. Op::Re on a numeric date renders it with format_millis before matching.
  • adr/parquet.md documents the millisecond read form and the partial selection.
  • New tests: millis vs RFC 3339 batch_to_rows, render_row, top-k pagination and tie order, date filters on the numeric read form, canonical dates after include/exclude and purge, and canonical dates after the 65-part compaction.

Benchmark (same host, NATS + ClickHouse up, cargo bench -p eve_e2e -- tsdb)

Benchmark Before After Change
tsdb query/parquet 8.45 ms 4.88 ms -42%
tsdb query/clickhouse 5.92 ms 6.16 ms noise
tsdb purge/parquet 2.18 ms 1.74 ms -20%
tsdb persistent projection/parquet/100 11.30 ms 10.20 ms -10%
tsdb insert/parquet/1000 0.91 ms 0.93 ms noise
tsdb insert/parquet/1 0.25 ms 0.17 ms noise

Parquet now answers this filtered/sorted page faster than ClickHouse (4.88 ms vs 6.16 ms); the insert gap remains unchanged and is dominated by ClickHouse's async-insert flush, not by this PR.

Verification

cargo fmt --all -- --check
cargo clippy -p eve_tsdb_parquet -p eve_e2e --all-targets -- -D warnings
cargo test -p eve_tsdb_parquet                 # 17 passed
cargo test -p eve_e2e --test tsdb --test app    # 14 + 2 passed
NATS_URL=nats://127.0.0.1:4222 \
CLICKHOUSE_URL=http://root:root1234@127.0.0.1:8123 \
  cargo bench -p eve_e2e -- tsdb

Not in this PR

Arrow compute kernels, projection pushdown (read only needed columns), parallel part scans, row-group pruning and precomputed lowercase sort keys remain possible follow-ups; this PR only removes the JSON/date round-trip and the full sort from the hot path.

Optimize the `eve_tsdb_parquet` read path. The `tsdb query` benchmark (10,000 seeded rows, `value=gt=5000`, sort `+date`, limit 100) drops from ~8.45 ms to ~4.88 ms without changing the public API, query results or the on-disk format. ## Why it was slow 1. Every Arrow `Timestamp(ms)` was formatted to an RFC 3339 string for every scanned row. 2. The sort comparator then parsed those strings back to milliseconds on every comparison (~60k comparisons for 5,000 rows). 3. `raw_page` sorted every matching row before applying `offset`/`limit`. 4. Dates were rendered for all 10,000 rows even though only the 100-row page is returned. ## Changes - **Internal date form is UTC milliseconds.** `table::DateMode::{Millis, Rfc3339}` selects the representation; all internal reads (query, purge, export, compaction) use `Millis`, while `store::decode_part` keeps `Rfc3339` for the public `ParquetCodec` contract. `TableSchema::render_row` converts only the returned page back to the canonical string. `rows_to_batch` already accepts a numeric millisecond date, so purge/export/import/compaction are unchanged on disk. - **Stable top-k pagination.** `filter::sort_and_paginate` uses `select_nth_unstable_by` for the first `offset + limit` rows and sorts only that prefix when the page does not cover the whole result; the original row index is the final tie-break, so equal keys keep the old stable order. No limit still uses a full sort. - **Regex on dates stays correct.** `Op::Re` on a numeric date renders it with `format_millis` before matching. - `adr/parquet.md` documents the millisecond read form and the partial selection. - New tests: millis vs RFC 3339 `batch_to_rows`, `render_row`, top-k pagination and tie order, date filters on the numeric read form, canonical dates after include/exclude and purge, and canonical dates after the 65-part compaction. ## Benchmark (same host, NATS + ClickHouse up, `cargo bench -p eve_e2e -- tsdb`) | Benchmark | Before | After | Change | |---|---:|---:|---:| | `tsdb query/parquet` | 8.45 ms | 4.88 ms | **-42%** | | `tsdb query/clickhouse` | 5.92 ms | 6.16 ms | noise | | `tsdb purge/parquet` | 2.18 ms | 1.74 ms | -20% | | `tsdb persistent projection/parquet/100` | 11.30 ms | 10.20 ms | -10% | | `tsdb insert/parquet/1000` | 0.91 ms | 0.93 ms | noise | | `tsdb insert/parquet/1` | 0.25 ms | 0.17 ms | noise | Parquet now answers this filtered/sorted page faster than ClickHouse (4.88 ms vs 6.16 ms); the insert gap remains unchanged and is dominated by ClickHouse's async-insert flush, not by this PR. ## Verification ```sh cargo fmt --all -- --check cargo clippy -p eve_tsdb_parquet -p eve_e2e --all-targets -- -D warnings cargo test -p eve_tsdb_parquet # 17 passed cargo test -p eve_e2e --test tsdb --test app # 14 + 2 passed NATS_URL=nats://127.0.0.1:4222 \ CLICKHOUSE_URL=http://root:root1234@127.0.0.1:8123 \ cargo bench -p eve_e2e -- tsdb ``` ## Not in this PR Arrow compute kernels, projection pushdown (read only needed columns), parallel part scans, row-group pruning and precomputed lowercase sort keys remain possible follow-ups; this PR only removes the JSON/date round-trip and the full sort from the hot path.
aleksei deleted branch perf/tsdb-parquet-query 2026-10-21 11:17:02 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
zoo/eve!8
No description provided.