Skip to content

perf: skip mapNodes dedup map in FindNodes#577

Open
jvoisin wants to merge 1 commit into
PuerkitoBio:masterfrom
jvoisin:another_dedup
Open

perf: skip mapNodes dedup map in FindNodes#577
jvoisin wants to merge 1 commit into
PuerkitoBio:masterfrom
jvoisin:another_dedup

Conversation

@jvoisin

@jvoisin jvoisin commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Each source node passed to FindNodes maps to at most itself (when it is a descendant of the current selection), so there is nothing to deduplicate across distinct sources. Replace the mapNodes call and its per-node callback/slice allocations with a direct append loop.

Duplicate input nodes are still discarded with a cheap isInSlice check (run before the more expensive sliceContains tree walk) so the resulting Selection stays a proper set, matching the previous behaviour.

benchstat:
sec/op -43.68%
B/op -82.00%
allocs 85 -> 9

Add TestFindNodesDuplicateInput to cover the duplicate-input case.

Each source node passed to FindNodes maps to at most itself (when it is a
descendant of the current selection), so there is nothing to deduplicate
across distinct sources. Replace the mapNodes call and its per-node
callback/slice allocations with a direct append loop.

Duplicate input nodes are still discarded with a cheap isInSlice check
(run before the more expensive sliceContains tree walk) so the resulting
Selection stays a proper set, matching the previous behaviour.

benchstat:
  sec/op  -43.68%
  B/op    -82.00%
  allocs    85 -> 9

Add TestFindNodesDuplicateInput to cover the duplicate-input case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant