Skip to content

perf: presize set in appendWithoutDuplicates to final expected size#565

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

perf: presize set in appendWithoutDuplicates to final expected size#565
jvoisin wants to merge 1 commit into
PuerkitoBio:masterfrom
jvoisin:prez

Conversation

@jvoisin
Copy link
Copy Markdown
Contributor

@jvoisin jvoisin commented May 29, 2026

BenchmarkAddNodesBig (DocW().Find("li") duplicated to ~1500 nodes, then AddNodes onto an empty selection), -count=20:

             sec/op             B/op           allocs/op
before    214.3µs ±12%     27.58Ki ±0%       24
after     104.8µs ±24%     45.24Ki ±0%       16
              -51%             +64%          -33%

The B/op increase is the cost of presizing the map to its final capacity in one shot rather than letting the runtime grow it through smaller bucket arrays (which are freed but counted in total bytes allocated). Peak resident memory is comparable.

BenchmarkAddNodesBig (DocW().Find("li") duplicated to ~1500 nodes,
then AddNodes onto an empty selection), -count=20:

                 sec/op             B/op           allocs/op
    before    214.3µs ±12%     27.58Ki ±0%       24
    after     104.8µs ±24%     45.24Ki ±0%       16
                  -51%             +64%          -33%

The B/op increase is the cost of presizing the map to its final
capacity in one shot rather than letting the runtime grow it
through smaller bucket arrays (which are freed but counted in
total bytes allocated). Peak resident memory is comparable.
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