6 Commits
Author SHA1 Message Date
jvoisin 45d35d506a perf: avoid per-node Selection allocation in winnow Not path
The winnow() "Not" path routed through grep(), which called
newSingleSelection() for every node, allocating a Selection and
a 1-element []*html.Node slice on the heap per node, only to
immediately unwrap it via s.Get(0) for m.Match().
This commit call m.Match(n) directly and pre-allocate the result slice.

It also adds BenchmarkNotMatcher to isolate the winnow path from
compileMatcher overhead.

Here are my local benchmark results, for BenchmarkNotMatcher with 373 <li>
nodes, and a pre-compiled matcher:

old ns/op   new ns/op   delta
22750       19350       ~-15%

old B/op    new B/op    delta
9384        3120        -66.7%

old allocs  new allocs  delta
11          2           -81.8%
2026-05-23 22:02:15 +02:00
38elements 109d3a6a56 Fix typo 2017-09-29 18:51:07 +09:00
Martin Angers ad8b3d8222 remove logging from benchmarks, validate expected result instead 2016-08-27 18:37:55 -04:00
Martin Angers 6669ef001f remove Document.Root, Document is itself a Selection (using embedded struct) 2012-10-14 12:28:27 -04:00
Martin Angers 23a9e4d290 add benchmarks for filter.go 2012-09-11 20:27:03 -04:00
Martin Angers 30f50b483f start add benchmarks for filter.go 2012-09-11 15:36:21 -04:00