Skip to content

perf: walk s.Nodes directly in HasNodes#558

Open
jvoisin wants to merge 1 commit into
PuerkitoBio:masterfrom
jvoisin:has-nodes-direct
Open

perf: walk s.Nodes directly in HasNodes#558
jvoisin wants to merge 1 commit into
PuerkitoBio:masterfrom
jvoisin:has-nodes-direct

Conversation

@jvoisin
Copy link
Copy Markdown
Contributor

@jvoisin jvoisin commented May 27, 2026

HasNodes routed through FilterFunction -> winnowFunction -> grep, which allocated a single-node Selection and a closure capture per source element, just to call sel.Contains(n) which is itself a one-iteration sliceContains over the wrapped node. This commit inlines a direct double loop over s.Nodes x nodes calling nodeContains, and push the result via pushStack.

name old allocs/op new allocs/op delta
Has-8 55.00 ± 0% 24.00 ± 0% -56.36% (p=0.000)
HasNodes-8 752.00 ± 0% 4.00 ± 0% -99.47% (p=0.000)
HasSelection-8 752.00 ± 0% 3.00 ± 0% -99.60% (p=0.000)

HasNodes routed through FilterFunction -> winnowFunction -> grep, which
allocated a single-node Selection and a closure capture per source element,
just to call sel.Contains(n) which is itself a one-iteration sliceContains over
the wrapped node. This commit inlines a direct double loop over s.Nodes x nodes
calling nodeContains, and push the result via pushStack.

name             old allocs/op  new allocs/op  delta
Has-8                  55.00 ± 0%     24.00 ± 0%  -56.36% (p=0.000)
HasNodes-8            752.00 ± 0%      4.00 ± 0%  -99.47% (p=0.000)
HasSelection-8        752.00 ± 0%      3.00 ± 0%  -99.60% (p=0.000)
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