mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
Ideas employed
- reorder fields so that mask is before the string
- use POPCNT to estimate allocation size
- allocate late on demand
- pre-compute mask of known flags
- bail out when known flags are handled
This yields improvements in most of the benchmarks:
Before:
BenchmarkUnmountFlagsToOptsAllMissing-4 200000000 6.07 ns/op
BenchmarkUnmountFlagsToOptsMixed-4 50000000 36.8 ns/op
BenchmarkUnmountFlagsToOptsAllPresent-4 10000000 158 ns/op
BenchmarkMountFlagsToOptsAllMissing-4 200000000 9.93 ns/op
BenchmarkMountFlagsToOptsAllPresent-4 10000000 230 ns/op
BenchmarkMountFlagsToOptsMixed-4 30000000 41.4 ns/op
BenchmarkMountFlagsToOptsTypical-4 30000000 41.8 ns/op
After:
BenchmarkUnmountFlagsToOptsAllMissing-4 500000000 3.41 ns/op
BenchmarkUnmountFlagsToOptsMixed-4 30000000 54.3 ns/op
BenchmarkUnmountFlagsToOptsAllPresent-4 20000000 63.8 ns/op
BenchmarkMountFlagsToOptsAllMissing-4 500000000 3.71 ns/op
BenchmarkMountFlagsToOptsAllPresent-4 20000000 83.6 ns/op
BenchmarkMountFlagsToOptsMixed-4 20000000 51.5 ns/op
BenchmarkMountFlagsToOptsTypical-4 50000000 33.2 ns/op
I've also added a "typical" benchmark with one known flag only.
Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>