collection: share kernel BTF when loading a collection#1778
Conversation
|
@patrickpichler could you give this branch a try and let me know what you think? |
|
Sorry for the super late response. I did run the benchmark again and here are the results: With your change With the optimization I did in the draft PR (#1690) When performing a single run, the total number of allocated memory according to pprof went down from I guess there are a few more ways on how to reduce the number of allocations, but for my use case, this should be good enough. Thanks a lot! |
37ff654 to
feb0a51
Compare
We currently create a new copy of kernel BTF when loading each program in a
collection, which is quite expensive.
Introduce a new type btf.Cache which allows re-using kernel BTF as-needed.
As an optimisation, the Cache is opportunistically populated from the global
cache on creation.
core: 1
goos: linux
goarch: amd64
pkg: github.com/cilium/ebpf
cpu: 13th Gen Intel(R) Core(TM) i7-1365U
│ base.txt │ cache.txt │
│ sec/op │ sec/op vs base │
NewCollectionManyProgs 347.84m ± 1% 14.54m ± 2% -95.82% (p=0.002 n=6)
│ base.txt │ cache.txt │
│ B/op │ B/op vs base │
NewCollectionManyProgs 108.056Mi ± 0% 3.841Mi ± 0% -96.44% (p=0.002 n=6)
│ base.txt │ cache.txt │
│ allocs/op │ allocs/op vs base │
NewCollectionManyProgs 1026.83k ± 0% 38.04k ± 0% -96.30% (p=0.002 n=6)
Signed-off-by: Lorenz Bauer <[email protected]>
dylandreimerink
left a comment
There was a problem hiding this comment.
This seems sane to me 🚀
Uh oh!
There was an error while loading. Please reload this page.