ebpf
ebpf copied to clipboard
btf: introduce caching string table to speed up ext info loading
https://github.com/cilium/ebpf/pull/1772 introduced lazy loading of strings from string tables. It helps a lot when querying types, but when parsing line infos, we end up querying multiple times the same offest (especially the file name), and we currently create a new string each time.
This PR deduplicates this allocation by caching the string when parsing line info.
Benchmarks:
$ go test -exec=sudo -benchmem -run=^\$ -bench=^BenchmarkELF github.com/cilium/ebpf
With the elf file present in this repo (testdata/loader-el.elf):
goos: linux
goarch: arm64
pkg: github.com/cilium/ebpf
│ before.txt │ after.txt │
│ sec/op │ sec/op vs base │
ELFLoader-4 379.4µ ± 4% 377.9µ ± 2% ~ (p=0.912 n=10)
│ before.txt │ after.txt │
│ B/op │ B/op vs base │
ELFLoader-4 187.8Ki ± 0% 186.8Ki ± 0% -0.49% (p=0.000 n=10)
│ before.txt │ after.txt │
│ allocs/op │ allocs/op vs base │
ELFLoader-4 1.470k ± 0% 1.402k ± 0% -4.63% (p=0.000 n=10)
On a 18MiB elf file:
goos: linux
goarch: arm64
pkg: github.com/cilium/ebpf
│ before.txt │ after.txt │
│ sec/op │ sec/op vs base │
ELFLoader-4 83.81m ± 2% 79.17m ± 2% -5.54% (p=0.000 n=10)
│ before.txt │ after.txt │
│ B/op │ B/op vs base │
ELFLoader-4 88.81Mi ± 0% 67.67Mi ± 0% -23.80% (p=0.000 n=10)
│ before.txt │ after.txt │
│ allocs/op │ allocs/op vs base │
ELFLoader-4 1132.2k ± 0% 834.3k ± 0% -26.31% (p=0.000 n=10)