Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load kernel BTF spec once when creating a new collection
When creating a new collection without specifying the `KernelTypes` in the `ProgramOptions`, the kernel BTF is implicitly loaded. For this the `btf.LoadKernelSpec()` helper is used. Even though the spec is only loaded once, this operation cause a lot of memory churn, as the kernel spec is being copied each time the function get called. This becomes an issue when a collection with lots of programs is loaded in a resource limited environment. This commit initializes an missing `KernelTypes` field with the BTF kernel spec, getting rid of the subsequent calls of `BTF.Copy()`. This greatly reduces the number of allocations/op when running the `BenchmarkNewCollectionManyProgs` benchmark. Here are the results: Previous: BenchmarkNewCollectionManyProgs-4 12 98443414 ns/op 116779863 B/op 403964 allocs/op With optimization: BenchmarkNewCollectionManyProgs-4 184 5807742 ns/op 4134444 B/op 17325 allocs/op
- Loading branch information