Repository navigation
[Performance] Short-circuit NodeComparator::areNodesEqual before printing - #8752
Merged
Merged
Conversation
…ting Bail out early in areNodesEqual() before the expensive printWithoutComments() call: - return false when either node is null (also avoids printing a null node) - return false when the two single nodes are of a different class, since nodes of different classes can never print as equal This skips the print+compare round-trip on the common unequal case.
TomasVotruba
force-pushed
the
tv-perf-5
branch
from
October 21, 2026 20:47
27a4b2a to
58de55e
Compare
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.
Adds two cheap early bail-outs to
areNodesEqual()before the expensiveprintWithoutComments()round-trip:falsewhen either node isnull- also avoids calling the printer on a null nodefalsewhen the two single nodes are of a different class - nodes of different classes can never print as equal, so the print+compare is pure overheadBehavior is unchanged; only the common unequal case gets faster.
Benchmark
bench/node_comparator_short_circuit_bench.php- 1.8M calls over a realistic blend of pair types (null, different-class, same-class equal/unequal), CPU time (user+sys), warmup excluded, 3 runs each branch:~1.69x faster, ~41% CPU cut on this blend (5 of 9 pairs now skip the print). The win scales with how many hot-path pairs are null or different-class; same-class pairs are unchanged.