Skip to content

perf(iceberg): eliminate per-file footer round-trips + raise decode concurrency (PR-2) - #1482

Closed
aaj3f wants to merge 9 commits into
perf/r2rml-pr1-count-manifestfrom
perf/r2rml-pr2-decode-levers
Closed

aaj3f wants to merge 9 commits into
perf/r2rml-pr1-count-manifestfrom
perf/r2rml-pr2-decode-levers

Conversation

@aaj3f

@aaj3f aaj3f commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Roadmap PR-2 (docs/audit/2026-07-virtual-dataset-perf/ROADMAP.md): the H1 decode-wall lever set, driven by the measurement in 06-per-file-cost.md (committed here as phase 1).

The finding (phase 1, measurement)

The ~200ms/file fixed cost behind the fact-scan DNF wall is one thing: the Parquet footer read — 2 sequential S3 range GETs per file that never warm, because (1) the in-memory footer cache caps at 64 entries vs 7,670 files per fact table, and (2) read_metadata range-reads footers from source S3 even when the whole file is already in the local disk cache. Actual decode: 0.13ms. Spawn/channel: 0.17ms. Arithmetic reconciles the wall exactly: 7,670 × 195ms ÷ 8 = 187s ≈ the observed DNF.

The levers (phase 2)

Lever A — footer-from-fetched-bytes (FLUREE_ICEBERG_FOOTER_FROM_CACHE, default on): for files in the whole-file-fetch tiers, parse the footer from bytes we fetch anyway. A2: disk-cache hit ⇒ footer+data served locally. A1: cheap ≤32MB tier ⇒ one whole-file GET (3 S3 RTs → 1). Sparse-range/large files keep today's footer-first path unchanged — no forced whole-file fetches. Switch off restores prior behavior byte-for-byte (verified live: footer_read snaps back to ~208ms/file).

Lever B — decode concurrency default min(cpus,8) → min(cpus,32): pointwise ≥ the old default on every core count (2-core Lambda unchanged); FLUREE_ICEBERG_SCAN_CONCURRENCY still wins; 32 is the measured contention ceiling (8→32 = 2.1× on a 91-file scan, mild creep past c=16).

Live results (SF01, hash-verified against native oracles)

measure before after
warm per-file total 191ms 0.67ms (285×)
warm footer_read 190,627µs 21µs
q011 (91-file fact scan) 3.27s 620ms
q001 / q022 sentinels 2.19s / 675ms 1.06s / 440ms
q046 (ORDER BY, 7,670 files) DNF@180s 45.9s fully cold (footer 20µs/file; residual = pure data-fetch GETs)

q046 completing cold means the fact-scan DNF class now completes; warm repeats are seconds. Composes with PR-1 (COUNT from manifest) and points at PR-8 (the remaining catalog/REST floor).

Gates

1–3. fluree-db-query / fluree-db-api / fluree-db-iceberg --lib --tests — green (161/…/full suites). One grp_misc failure fully attributed: it_minmax_fast_path_fired documents it must be "the only test in this binary" (thread-local tracing subscriber) but is bundled with 241 siblings — pre-existing order fragility perturbed by our added callsites, 237/237 pass single-threaded, passes solo both ways, and base-vs-levers full-bin A/B confirms interleaving not behavior. Test-infra follow-up: use set_global_default capture per the known interest-cache pitfall, or restore its own bin.
4. Native corpus 54/54, 0 hash mismatches (three runs). Perf noise per the environmental protocol (concurrent unrelated builds observed; q009/q010 outliers queued for idle re-verification — levers are structurally Iceberg-only).
5. Live virtual: table above; fire/decline and switch semantics proven via span counters (footer_read 21µs on ⇄ 208ms off).

Phase-1 sub-spans (read_footer/fetch_bytes/decode/plan_columns) are kept as permanent counters — they're the regression evidence for this exact class.

Stacks on #1478 (PR-1) ← #1476 (PR-0) ← #1475 (bench) ← #1450.

aaj3f added 2 commits July 11, 2026 20:10
…the footer read (PR-2 phase 1)

Measured (q011 91 files + q046 7,670 files, cold vs warm): the fixed
per-file cost is the Parquet footer read — 2 sequential S3 range GETs
(~190ms) that never warm because (1) ParquetFooterCache caps at 64 entries
vs 7,670 files/table, and (2) read_metadata range-reads the footer from
SOURCE S3 even when the whole file is in the local disk cache. Decode is
0.13ms; spawn/channel 0.17ms; whole-file fetch warms to 0.23ms. Concurrency
clamp verified min(cpus,8); sweep 8->32 = 2.1x with per-file wall flat.
Reconciles the DNF wall exactly: 7,670 x 195ms / 8 = 187s.

Adds 4 additive debug sub-spans (footer/fetch/decode/plan) to the parquet
read path + bench allowlist — the ongoing counters that will verify the
PR-2 levers.
…oncurrency (PR-2)

The fact-scan DNF wall was one cost: ~200ms/file of Parquet footer reads —
2 sequential S3 range GETs that never warmed (footer cache capped at 64
entries vs 7,670 files/table; footers range-read from source S3 even with
the whole file in the local disk cache). Decode itself is ~0.1ms.

Lever A (FLUREE_ICEBERG_FOOTER_FROM_CACHE, default on): for files in the
whole-file-fetch tiers, parse the footer from the bytes we fetch anyway —
disk-cache hit serves footer+data locally (A2); the cheap <=32MB tier
collapses 3 S3 round-trips to 1 (A1). Sparse-range/large files keep the
existing footer-first path unchanged. Switch off restores prior behavior
exactly (verified: footer_read 208ms/file, prior wall reproduced).

Lever B: decode concurrency default min(cpus,8) -> min(cpus,32) — pointwise
never below the old default; FLUREE_ICEBERG_SCAN_CONCURRENCY still wins;
32 = measured contention ceiling (8->32 = 2.1x on a 91-file scan).

Live SF01: warm per-file 191ms -> 0.67ms (footer 190,627us -> 21us, n=91);
q011 3.27s -> 620ms, q001 2.19s -> 1.06s, q022 675 -> 440ms, hash-verified.
q046 (ORDER BY over 7,670 files) FLIPS DNF@180s -> 45.9s fully cold
(footer 20us/file cold; residual is pure data-fetch S3 GETs). Native corpus
0 hash mismatches. grp_misc multilang flake explained: pre-existing
thread-local-subscriber order dependence (test doc says 'only test in this
binary'; bundled with 241 siblings), perturbed by new callsites — 237/237
single-threaded; separate test-infra follow-up.
@aaj3f

aaj3f commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Precision note on the kill-switch claim in the body/commit: FLUREE_ICEBERG_FOOTER_FROM_CACHE=0 restores the footer path exactly (span-verified: read_footer 21µs → 207,898µs/file, the 2-round-trip behavior), but Lever B's concurrency default is deliberately NOT gated by that switch — so switch-off wall time is 1,860ms vs the true pre-PR 2,966ms on the same query. To reproduce pre-PR behavior fully, pin both FLUREE_ICEBERG_FOOTER_FROM_CACHE=0 and FLUREE_ICEBERG_SCAN_CONCURRENCY=8. Also: the q046 45.9s cold figure is on a 16-core host (Lever B is core-bound, min(cpus,32) ⇒ 16-way here); a ≥32-core host or the env override reaches the projected ~23s.

aaj3f added 7 commits July 13, 2026 18:03
cargo fmt --all --check fails on four hunks of this PR's own delta in
fluree-db-iceberg/src/io/send_parquet.rs with rustfmt from stable
1.97.0 — what CI's dtolnay/rust-toolchain@stable resolves. CI never
ran here (ci.yml triggers only on base=main), flagged by the #1476
review stack-wide note.
… guard

The four per-file cost-decomposition spans (read_footer / plan_columns /
fetch_bytes / decode) were added to SPAN_ALLOWLIST without rows in the
rename-guard `sites` table or the module doc table, so
allowlist_literals_exist_at_engine_callsites failed at this branch's
head — latent until now because PR-2's gate list didn't include the
fluree-bench-virtual unit tests. Cite their real callsite
(fluree-db-iceberg/src/io/send_parquet.rs, read_task_small_file) so the
guard re-checks them like every other counter.
…k switch idiom, PR-2 residual

Three items from the #1482 review:

- The Lever B comment claimed per-host resident memory "never exceeds
  today's core-bound footprint" — wrong: the previous default capped
  in-flight decodes at 8 regardless of cores, so a 16-core host now
  runs 16 and a >=32-core host 32 (up to 4x the prior in-flight buffer
  bytes, each file <=32MB whole-file / <=64MB sparse-buffer). Restate
  the trade honestly: the sweep data and the tiny-file fact-table shape
  justify it, and the env override is the pressure valve in both
  directions (raise on low-core hosts, lower on memory-tight ones).

- footer_from_cache_enabled() re-read the env var (process env lock
  included) once per file task while the rest of the R2RML switch
  family (catalog_session::cache_enabled, crawl_expand_enabled, PR-3's
  star_tm_prune_enabled) reads once through a OnceLock. Unify on the
  family idiom, and align the disable-token set with the family:
  0/false/off/no (was 0/false only — previously =off silently left the
  lever enabled). No runtime re-toggling use exists: the only three
  references were the doc, the fn, and the callsite, and the live A/B
  protocol sets the env at process launch.

- ROADMAP: record the PR-2 residual the review spotted — a 32-64MB
  file with no local cache copy and a broad (>=50%-share) projection is
  still fetched whole by admit_whole_file's broad branch but pays the
  2-RT footer read first, structurally: broadness is computed from
  footer metadata (projected column-chunk bytes), so covering that tier
  means speculative whole fetches — a different trade than Lever A's
  bytes-we-fetch-anyway invariant. Deliberately left conservative.

The review's blocking fmt item does not reproduce at the reviewed head
(8dcd5cf) with CI-parity rustfmt from stable 1.97.0: the three named
files were each formatted in restack-era fmt commits (r2rml.rs in
f8f5206, send_parquet.rs in a254f42, spans.rs in b5ffcd1), and
cargo fmt --all --check exits 0 before and after this commit.

Gates at this head: fluree-db-iceberg --lib --tests 180/180,
count_shortcut 7/7, scoped clippy (--lib --tests) 0 warnings, fmt
clean. (clippy --all-targets fails compiling the smoke_minio example
featureless — pre-existing: the example lacks required-features="aws",
unrelated to this delta.)
aaj3f added a commit that referenced this pull request Jul 14, 2026
…ormation gap on record

Two optional items from the PR-3 review:

- One switch helper for the R2RML family: the five fluree-db-query
  boolean switches (LIMIT_PUSHDOWN, STAR_TM_PRUNE, SCAN_CACHE,
  FILTER_CONSUMPTION, CRAWL_CLASS_FUSION) had drifted into two falsy
  spelling sets (0/false/off vs 0/false/off/no). All now route through
  r2rml::env_switch_enabled (0/false/off/no — the superset; the only
  behavior change is that "no" now disables the three switches that
  previously ignored it, aligning with the documented family intent).
  The fluree-db-api crawl helper and the fluree-db-iceberg footer
  switch already match these spellings; cross-crate symbol sharing
  isn't possible without a new common home, so they stay mirrored and
  are cross-referenced from the helper doc.

- F10 filed: the pre-existing split-member star-formation gap
  (required same-subject members split across template-sharing
  TriplesMaps yield zero star rows; native would subject-join) is now
  a registered residual in 04-findings-register.md plus a ROADMAP
  §PR-3 residual note, with cross-refs at the two seams
  (tm_passes_star_prune doc, rewrite star-fusion loop). Pre-existing
  and preserved (not caused) by fix (a)'s intersection prune; future
  fix in the rewrite — refuse to fuse when no TM covers all members.

The review's blocking fmt item was already cleared by the per-PR
rustfmt commits (cargo fmt --all --check green at this HEAD); the
OnceLock-idiom aside for the #1482 footer switch landed in 0590613.

Gates: fluree-db-query 1260/1260 (nextest); scoped clippy 0 errors;
fmt --all --check green.
@aaj3f

aaj3f commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Consolidating at maintainer request. #1482 (PR-2 — per-file Parquet footer round-trip elimination + higher decode concurrency) is carried forward in #1507 (the R2RML/Iceberg virtual-dataset performance program), which brings the #1475–#1507 lineage forward as a single reviewable unit. Its verification of record is the program's corpus benchmark, published as C2-bench-wave1.md (native == virtual, 0 hash mismatches). The pre-consolidation branch tip is preserved at tag archive/pre-refactor-2026-07-21/perf_r2rml-pr2-decode-levers — no history was rewritten. Closing in favor of #1507; discussion continues there.

@aaj3f aaj3f closed this Jul 21, 2026
@aaj3f
aaj3f deleted the perf/r2rml-pr2-decode-levers branch July 30, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant