perf: scan adjacent element directly in Next/Prev sibling traversal#573
Open
jvoisin wants to merge 1 commit into
Open
perf: scan adjacent element directly in Next/Prev sibling traversal#573jvoisin wants to merge 1 commit into
jvoisin wants to merge 1 commit into
Conversation
Next() and Prev() request a single sibling per source node, and distinct
source nodes always have distinct immediate siblings, so the results can
never contain duplicates. Routing them through mapNodes (which allocates a
dedup map and a throwaway one-element slice per node) and the general
getChildrenWithSiblingType iterator is suboptimal.
This commit adds a dedicated fast path in getSiblingNodes that scans straight
to the adjacent element node and appends into a presized slice, skipping the
dedup map and the iterator closure entirely.
benchstat (count=10, all p=0.000):
| old | new |
| allocs | allocs vs base |
Next-8 | 60.00 | 2.000 -96.67% |
Prev-8 | 60.00 | 2.000 -96.67% |
NextFiltered-8| 65.00 | 7.000 -89.23% |
PrevFiltered-8| 65.00 | 7.000 -89.23% |
sec/op: Next -89%, Prev -92%, Filtered variants -72%
B/op: ~-80%
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.
Next() and Prev() request a single sibling per source node, and distinct source nodes always have distinct immediate siblings, so the results can never contain duplicates. Routing them through mapNodes (which allocates a dedup map and a throwaway one-element slice per node) and the general getChildrenWithSiblingType iterator is suboptimal.
This commit adds a dedicated fast path in getSiblingNodes that scans straight to the adjacent element node and appends into a presized slice, skipping the dedup map and the iterator closure entirely.
benchstat (count=10, all p=0.000):