datasource: opt-in open-ahead so FileStream overlaps the next file's open with scanning - #77
Merged
Merged
Conversation
…open with scanning The morsel-driven FileStream (55.0) opens files strictly one after another per partition: the next file's footer/page-index/bloom-filter I/O starts only once the active reader is exhausted. Before the rewrite the next file's open future was polled while the current file streamed, hiding per-file open latency. On many-file scans over object storage that latency is now exposed on every file (TPC-H SF100 Q1: DataSourceExec time_elapsed_opening 2.2 s -> 82.3 s summed over 5 partitions, ~16 s of wall). Add `datafusion.execution.file_stream_open_ahead` (default false). When set, ScanState claims the next file while a reader is active and drives its planning until it either yields a ready morsel or blocks on its single outstanding I/O, which poll_scan resolves ahead of polling the reader. At most one file is in flight ahead of the reader, so the extra footprint is one file's metadata per partition. The opening timer then measures only the exposed wait (no reader to drain). Default off keeps the existing behaviour and snapshots byte-identical. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012m5Yx6yEpZsacqAhZotgkT
…change) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012m5Yx6yEpZsacqAhZotgkT
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012m5Yx6yEpZsacqAhZotgkT
…/file-stream-open-ahead
osipovartem
approved these changes
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
datafusion.execution.file_stream_open_ahead(defaultfalse). When enabled, eachFileStreampartition claims its next file while the active reader is still producing batches and drives that file's planning until it either yields a ready morsel or blocks on its single outstanding I/O, whichpoll_scanresolves ahead of polling the reader. At most one file is in flight ahead of the reader, so the extra footprint is one file's metadata per partition.Why
The morsel-driven
FileStream(apache#21342, apache#21351) opens files strictly one after another per partition ("single I/O outstanding", next file only once the reader is drained). Before the rewrite the next file's open future was polled while the current file streamed. On many-file scans over object storage the per-file open latency is now exposed on every file. Measured on Embucket's SPCS M node, TPC-H SF100 Q1 (929 Iceberg/parquet lineitem files, 5 partitions):DataSourceExectime_elapsed_opening2.2 s (DF 53) → 87.6 s (DF 55, summed over partitions) withmetadata_load_timeunchanged (~90 s); with this option on, the exposed opening time drops to 1.9 s and the same ~98 s of metadata loading overlaps with reads.Measured (Embucket rustice, SPCS M, cold sweeps, same image, env toggle only)
No query slower than control (per-query table in
benchmark-results/bench-v6/scan-open-overlap/of the rustice repo). Q6 on a warm metadata cache also improves (scanning-until-data 31.0 s → 23.4 s) because the next file's CPU planning (filter preparation, statistics pruning, stream construction) is overlapped too.Notes
time_elapsed_openingcounts only the wait that is actually exposed (no reader left to drain); the non-exposed open time shows up inmetadata_load_timeas before.morsel_open_ahead_overlaps_next_file_iodocuments the interleaving.information_schema.sltupdated;cargo test -p datafusion-datasource --lib file_stream28/28;cargo clippy -p datafusion-datasource --all-targets -D warningsclean.🤖 Generated with Claude Code
https://claude.ai/code/session_012m5Yx6yEpZsacqAhZotgkT