With benchstat result comparing the linear and indexed searches, we saw that indexed search method is way faster than linear.
If we look at the CPU profile, the resources are distributed across map functions, and runtime.memequal has a cumulative value of 5.88%, compared to the linear counterpart having 50.33%. This shows what kind of operation the indexed method is composed of.
go test -run '^$' \
-bench '^BenchmarkCountAllowedEvents$/^implementation=indexed$' \
-benchtime=5s \
-cpuprofile=/tmp/codec01-allowlist-indexed-cpu.pprof
goos: linux
goarch: arm64
pkg: codec01
BenchmarkCountAllowedEvents/implementation=indexed-12 509740 11687 ns/op 0 B/op 0 allocs/op
PASS
ok codec01 5.964s
go tool pprof -top \
/tmp/codec01-allowlist-indexed-cpu.pprof
File: codec01.test
Build ID: b577d07ab1e87fb7010e13f74ca1ed5b56d03c8a
Type: cpu
Time: 2026-10-26 20:56:21 PST
Duration: 5.96s, Total samples = 5.95s (99.82%)
Showing nodes accounting for 5.93s, 99.66% of 5.95s total
Dropped 19 nodes (cum <= 0.03s)
flat flat% sum% cum cum%
2.27s 38.15% 38.15% 5.18s 87.06% runtime.mapaccess2_faststr
1s 16.81% 54.96% 1s 16.81% aeshashbody
0.73s 12.27% 67.23% 5.92s 99.50% codec01.CountAllowedEventsIndexed (inline)
0.38s 6.39% 73.61% 0.38s 6.39% runtime.strhash
0.35s 5.88% 79.50% 0.35s 5.88% runtime.memequal
0.27s 4.54% 84.03% 0.27s 4.54% internal/runtime/maps.(*Map).directoryAt (inline)
0.25s 4.20% 88.24% 0.25s 4.20% internal/runtime/maps.(*groupsReference).group (inline)
0.22s 3.70% 91.93% 0.22s 3.70% internal/runtime/maps.(*Map).directoryIndex (inline)
0.22s 3.70% 95.63% 0.22s 3.70% internal/runtime/maps.bitsetFirst (inline)
0.21s 3.53% 99.16% 0.21s 3.53% internal/runtime/maps.ctrlGroupMatchH2 (inline)
0.03s 0.5% 99.66% 0.03s 0.5% runtime.futex
0 0% 99.66% 5.92s 99.50% codec01.BenchmarkCountAllowedEvents.func2
0 0% 99.66% 0.22s 3.70% internal/runtime/maps.bitset.first (inline)
0 0% 99.66% 0.21s 3.53% internal/runtime/maps.ctrlGroup.matchH2 (inline)
0 0% 99.66% 5.93s 99.66% testing.(*B).run1.func1
0 0% 99.66% 5.93s 99.66% testing.(*B).runN