perf: reuse metrics evaluator within manifests#3655
Open
dossett wants to merge 1 commit into
Open
Conversation
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.
I used CODEX to analyze this problem and create this PR. I've reviewed the code and test and stand by them. This summary is written completely by a human (me) other than very light copy editing by an LLM.
Profiling with py-spy showed that a great deal of time was being spent constructing the
_InclusiveMetricsEvaluatorobject. This object is used to interpret file statistics and determine whether a file might contain rows matching the scan predicate.This PR does two things:
CODEX summary follows:
Local scan planning applies Iceberg file metrics after partition filtering to determine whether each data file might contain matching rows. PyIceberg currently rebuilds the schema struct and rebinds the scan predicate every time that metrics evaluator is called. For manifests with many files, this repeats identical setup work and can dominate planning time.
This change reuses one
_InclusiveMetricsEvaluatorwithin each manifest task. The evaluator is initialized lazily when the first file survives partition filtering, then reused across that manifest's sequential entries. Each manifest receives a separate closure and evaluator, so the mutable file-metrics state is never shared across worker threads.Performance
The focused benchmark evaluates 1,000 files from one manifest-shaped batch using a 102-column schema and a 66-leaf predicate. Results are the mean of three in-process runs:
Revision | Mean | Best -- | -- | -- main | 1.491 s | 1.467 s This PR | 0.105 s | 0.104 sThat is approximately 14.2x faster for the isolated metrics-evaluation hot path.
The benchmark includes evaluator construction and file-metrics evaluation, but excludes catalog access, manifest I/O, partition filtering, residual computation, and downstream data reads. It is not an end-to-end query-runtime claim.
Testing
There are no API or result-semantics changes.
AI assistance
Codex assisted with implementation, test scaffolding, benchmark design, validation, and PR drafting.