skip to content
Alvin Lucillo

Indexed func source line view

/ 1 min read

Continuing from the yesterday’s point, we can see in the source code view that majority of the resources spent on the indexed search is on the map lookup, similar with the top functions view.

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             512224             11657 ns/op               0 B/op          0 allocs/op
PASS
ok      codec01 5.977s
go tool pprof \
  -list=codec01.CountAllowedEventsIndexed \
  /tmp/codec01-allowlist-indexed-cpu.pprof
Total: 5.97s
ROUTINE ======================== codec01.CountAllowedEventsIndexed
     740ms      5.96s (flat, cum) 99.83% of Total
         .          .     35:func CountAllowedEventsIndexed(eventNames []string, allowed map[string]struct{}) int {
         .          .     36:   count := 0
     460ms      460ms     37:   for _, name := range eventNames {
     280ms      5.50s     38:           if _, ok := allowed[name]; ok {
         .          .     39:                   count++
         .          .     40:           }
         .          .     41:   }
         .          .     42:   return count
         .          .     43:}