Skip to content

perf(scan): parse manifests concurrently - #3670

Merged
laskoviymishka merged 4 commits into
apache:mainfrom
CTTY:perf/parallel-manifest-parse
Nov 19, 2026
Merged

laskoviymishka merged 4 commits into
apache:mainfrom
CTTY:perf/parallel-manifest-parse

Conversation

@CTTY

@CTTY CTTY commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Which issue does this PR close?

What changes are included in this PR?

plan_files fetched manifests concurrently but parsed them one after another on the single task that drives the fetches. On a 601-manifest table about 80% of planning time was Manifest::try_from_avro_bytes on one core while the other workers idled.

ManifestReader now takes the table's Runtime and runs try_from_avro_bytes on runtime.cpu(); the fetch stays on the calling task. ObjectCache::get_manifest passes the runtime through, so up to concurrency_limit_manifest_files parses run in parallel. The transaction and drop-table paths go through the same reader and pick this up too.

Error handling is unchanged from the caller's view: a parse that panics or is cancelled surfaces as ErrorKind::Unexpected with the manifest path, and the plan stream ends with that error exactly as it does for a read error.

Two choices worth a reviewer's eye:

  • cpu().spawn rather than spawn_blocking, so parses stay within the worker count the embedding engine sized cpu() with. With a single shared runtime (Runtime::new / try_current), parses now share workers with IO; this matches what the entry stages in plan_files already do.
  • Only the parse moves. Spawning the whole per-manifest future on cpu() would run storage IO on a runtime an engine may build without an IO driver.

No public API change (make check-public-api is clean); new items are pub(crate).

Measurements

plan_files median, 4-worker runtime, TPC-H lineitem written by pyiceberg, local files:

table manifests before after
SF10 60 23.9 ms 7.0 ms
SF100 601 232.9 ms 65.4 ms

Are these changes tested?

Existing scan, object-cache and manifest tests cover the happy path. New tests:

  • scan::tests::test_plan_files_reports_{corrupt,missing}_manifest_as_error: a bad manifest fails the plan stream with ErrorKind::Unexpected and the manifest path, under a timeout so a swallowed error shows up as a failure rather than a hang.
  • scan::tests::test_plan_files_reports_cancelled_manifest_parse_as_error: a parse spawned on a shut-down cpu runtime fails the same way, exercising the JoinError path a panic would take.
  • spec::manifest::reader::tests::test_read_names_manifest_when_parse_is_cancelled: the reader itself attaches the manifest path to a JoinError, which carries none on its own.

cargo test -p iceberg --lib, cargo clippy --all-targets --all-features -D warnings, cargo fmt --check and make check-public-api are clean.

AI Disclosure

Drafted with AI assistance (Kiro), then reviewed, tested and benchmarked by me.

@CTTY
CTTY marked this pull request as draft November 11, 2026 04:52
@CTTY
CTTY marked this pull request as ready for review November 12, 2026 23:20
Comment thread crates/iceberg/src/io/object_cache.rs Resolved
@CTTY
CTTY force-pushed the perf/parallel-manifest-parse branch from bdf262b to b90f908 Compare November 16, 2026 22:48
CTTY and others added 3 commits November 16, 2026 22:51
TableScan::plan_files loads manifests from one task spawned on the io
runtime, and ManifestReader::read parsed each manifest on that task, so
the Avro decoding of every manifest in a snapshot ran one after another
while the other workers idled. Planning a 601-manifest table spent about
80% of its time in Manifest::try_from_avro_bytes on a single core.

ManifestReader now takes an optional Runtime and runs the parse on its
cpu handle, which is what Runtime::cpu is documented for; the fetch
stays on the calling io task. The scan passes the table's runtime
through ObjectCache::get_manifest, so up to
concurrency_limit_manifest_files parses run in parallel. ObjectCache
itself stores no runtime, so Table::with_runtime keeps sharing it.

Spawning the whole per-manifest future on io() would parallelise but
keep CPU work on the io runtime; spawning it on cpu() would run storage
IO on a runtime that an engine using iceberg-rust for planning only may
build without an IO driver. spawn rather than spawn_blocking keeps the
parse within the worker count the embedding engine sized cpu() with,
matching how the entry stages in plan_files already spawn their work.

A panic or cancellation in a parse surfaces as ErrorKind::Unexpected
through JoinHandle, and try_for_each_concurrent stops starting new
manifests on the first error, so the plan stream ends with that error
exactly as it does for a read error.

plan_bench medians (4 workers): SF10 23.9 -> 7.0 ms,
SF100 232.9 -> 65.4 ms.

(cherry picked from commit ce885c9)
…fest on JoinError

ManifestReader took an Option<Runtime>, which left two parse paths: the
spawned one the scan uses and an inline one that catalog::utils'
delete_data_files and several tests still took, so manifests read while
dropping a table were parsed serially. The runtime is now a constructor
argument, with_runtime is gone, and delete_data_files builds its reader
from the table. The inline-vs-spawned equivalence test goes with the
inline path it compared against.

A JoinError from the spawned parse (a panic, or a cpu runtime shut down
mid-plan) carried only "spawned task failed"; a parse error already names
the manifest. The reader now attaches the manifest path as context, so
every failure out of ManifestReader::read names the file. ObjectCache
wraps the error with the path too, which is why the scan-level
cancellation test passed without this; a reader-level test fails without
it. The scan-level test also asserts the path now, matching its corrupt
and missing siblings.
…ing it per call

ObjectCache::get_manifest took a &Runtime on every call, which threaded a
runtime through PlanContext, ManifestFileContext and validate_files_not_live
only to hand it to the ManifestReader it builds. The cache now owns the
runtime it parses on, taken at construction from the TableBuilder, and
get_manifest has its original signature again.

Table::with_runtime rebinds the cache through ObjectCache::with_runtime,
which clones the moka cache: a moka Cache is a handle to shared storage,
so the rebound table keeps every entry the original loaded while its
misses parse on the new runtime. The with_runtime test now checks both,
by building the table on a runtime it then shuts down: a cache that kept
the old runtime fails its first miss, and a cache that did not share
storage cannot answer for a manifest list whose file has been removed.
@CTTY
CTTY force-pushed the perf/parallel-manifest-parse branch from b90f908 to 780a428 Compare November 16, 2026 22:58

@JeonDaehong JeonDaehong 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.

Measured plan_files on main and on 780a428, alternating 3 rounds, 4 workers, local files, memory catalog, fresh Table per run so every manifest is parsed:

  • 600 manifests × 100 entries: 346–430 → 179–207 ms
  • 300 manifests × 2000 entries: 2302–2447 → 1550–1750 ms

So close to 2x when manifests are small, less when each holds many entries. LGTM.

let (metadata, mut entries) = self
.runtime
.cpu()
.spawn(async move { Manifest::try_from_avro_bytes(&bytes, Some(&location)) })

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.

Only the parse moves here, and the gain shrinks as manifests get larger (numbers in the review body), so the per-entry work after the parse is probably what's left on the calling task.

.await
// A `JoinError` (the parse panicked, or the cpu runtime shut down)
// names no manifest; a parse error already does.
.map_err(|err| err.with_context("manifest", &manifest_file.manifest_path))??;

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.

A panicking parse used to unwind through the planning task and now comes back as Unexpected with the manifest path. That seems like the better behavior, and test_read_names_manifest_when_parse_is_cancelled covers the same JoinError path.

@laskoviymishka laskoviymishka 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.

Thanks @CTTY for keeping the storage fetch off cpu() and for the reader-level cancellation test. As I read it, only the Avro parse moves, the public API is unchanged, and the shared-runtime case can't deadlock because plan_files already awaits cpu() spawns the same way. The two inline notes are about doc wording.

Comment thread crates/iceberg/src/scan/mod.rs Resolved
Comment thread crates/iceberg/src/table.rs Resolved
Table::manifest_reader and ManifestReader::read now say the parse runs on
the cpu runtime and fails with ErrorKind::Unexpected once that runtime has
shut down. The scan-level cancellation test credits ObjectCache's wrapper
for the manifest path, and points to the reader-level test that pins the
reader's own context.
@CTTY
CTTY requested a review from laskoviymishka November 19, 2026 00:29
@laskoviymishka
laskoviymishka added this pull request to the merge queue Nov 19, 2026
Merged via the queue into apache:main with commit 219078c Nov 19, 2026
24 checks passed
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.

perf: parse manifests concurrently in plan_files

3 participants