perf: O(1) PlanDataInjector lookup by op kind#4535
Open
schenksj wants to merge 2 commits into
Open
Conversation
PlanDataInjector.injectPlanData walked every operator in the tree against every registered injector (`for (injector <- injectors if injector.canInject(op))`) -- N operators x M injectors canInject calls -- even though most operators in any tree are non-scan and match no injector. Add `opStructCase` to the PlanDataInjector trait and key a Map[OpStructCase, PlanDataInjector]. Look up by op.getOpStructCase (O(1)) then a single canInject confirm; non-scan operators skip the iteration entirely. Pure performance change -- no behavior difference. Closes apache#4530 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
check-suites.py requires every *Suite.scala to appear in both pr_build_linux.yml and pr_build_macos.yml. Add the new PlanDataInjectorSuite alongside its sibling org.apache.spark.sql.comet suites. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Member
|
I'm not familiar with this code so will defer to @mbutrovich for review |
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.
Which issue does this PR close?
Closes #4530.
Rationale for this change
PlanDataInjector.injectPlanDatawalked every operator in the tree against every registered injector:That is N operators × M injectors
canInjectcalls, even though most operators in any tree are non-scan and match no injector.This is an independent micro-optimization, extracted from the Delta Lake contrib integration branch (which registers a third injector) purely to keep that PR focused; there is no functional dependency.
What changes are included in this PR?
def opStructCase: Operator.OpStructCaseto thePlanDataInjectortrait, implemented byIcebergPlanDataInjector(ICEBERG_SCAN) andNativeScanPlanDataInjector(NATIVE_SCAN).Map[Operator.OpStructCase, PlanDataInjector]and look up byop.getOpStructCase(O(1)), then run a singlecanInjectconfirm (which still inspects detail fields likehasCommon/!hasFilePartition). Non-scan operators skip the iteration entirely.Pure performance change — no behavior difference.
How are these changes tested?
PlanDataInjectorSuite: asserts a non-scan operator tree passes throughinjectPlanDataunchanged (exercises the O(1) miss path), and that each registered injector resolves back to itself via its declaredopStructCase(the kinds are distinct and the map is complete, so no injector is silently shadowed).CometExecSuite(126/0), which exercises native-scan plan-data injection end-to-end on every native query, passes unchanged — confirming the refactor preserves behavior.