Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btf: optimize stringTable to speed up vmlinux parsing #1203

Merged
merged 2 commits into from
Nov 7, 2023

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Nov 3, 2023

btf: remove unused stringTable.Marshal

The library now uses stringTableBuilder instead.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

btf: add fast path for string table offset 0 lookup

It turns out that the vast majority of string table lookups are for offset
zero, which is always defined to be the empty string.

This gives a good 14% speedup on my machine:

    goos: linux
   goarch: amd64
   pkg: github.com/cilium/ebpf/btf
   cpu: 12th Gen Intel(R) Core(TM) i7-1260P
                   │  base.txt   │              zero.txt              │
                   │   sec/op    │   sec/op     vs base               │
   ParseVmlinux-16   50.14m ± 7%   43.07m ± 3%  -14.10% (p=0.002 n=6)

                    │   base.txt   │           zero.txt            │
                   │     B/op     │     B/op      vs base         │
   ParseVmlinux-16   31.45Mi ± 0%   31.45Mi ± 0%  ~ (p=0.485 n=6)

                    │  base.txt   │           zero.txt           │
                   │  allocs/op  │  allocs/op   vs base         │
   ParseVmlinux-16   534.1k ± 0%   534.1k ± 0%  ~ (p=0.461 n=6)

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

The library now uses stringTableBuilder instead.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
It turns out that the vast majority of string table lookups are for
offset zero, which is always defined to be the empty string.

This gives a good 14% speedup on my machine:

    goos: linux
    goarch: amd64
    pkg: github.com/cilium/ebpf/btf
    cpu: 12th Gen Intel(R) Core(TM) i7-1260P
                    │  base.txt   │              zero.txt              │
                    │   sec/op    │   sec/op     vs base               │
    ParseVmlinux-16   50.14m ± 7%   43.07m ± 3%  -14.10% (p=0.002 n=6)

                    │   base.txt   │           zero.txt            │
                    │     B/op     │     B/op      vs base         │
    ParseVmlinux-16   31.45Mi ± 0%   31.45Mi ± 0%  ~ (p=0.485 n=6)

                    │  base.txt   │           zero.txt           │
                    │  allocs/op  │  allocs/op   vs base         │
    ParseVmlinux-16   534.1k ± 0%   534.1k ± 0%  ~ (p=0.461 n=6)

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
@lmb lmb merged commit 9d07628 into cilium:main Nov 7, 2023
13 checks passed
@lmb lmb deleted the btf-strings-opt branch November 7, 2023 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants