Skip to content

perf: find classes without building padded strings - #646

Open
g4lb wants to merge 1 commit into
PuerkitoBio:masterfrom
g4lb:class-index
Open

g4lb wants to merge 1 commit into
PuerkitoBio:masterfrom
g4lb:class-index

Conversation

@g4lb

@g4lb g4lb commented Nov 27, 2026

Copy link
Copy Markdown

The class functions built " "+class+" " for each node and class. The new classIndex finds the class without a new string. The output does not change.

Case Time Allocs
BenchmarkAddClass 33.4 → 23.7 µs (−29%)
BenchmarkRemoveClass 35.8 → 19.6 µs (−45%)
Add, 100 nodes −18% to −29%
Remove, 100 nodes −29% to −32% 1 fewer per node
Toggle, 100 nodes −30% to −34% 1 fewer per node
Add, 1 node −10% to −19%
Remove, 1 node −20% to −23% 1 fewer
Toggle, 1 node −22% to −26% 1 fewer

Each row except the first two covers 1 class, 3 classes and a class that is already present. Empty cells did not change. No benchmark was slower in all 3 code layouts (AMD EPYC 9V45, Go 1.27.4). Output matched on 1.12M random cases.

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