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

Eliminate binary.Read in instruction (un)marshaler #532

Merged
merged 2 commits into from
Jan 14, 2022

Conversation

ti-mo
Copy link
Collaborator

@ti-mo ti-mo commented Dec 20, 2021

This still needs to be fuzzed, but the gains are nice so far:

name                    old time/op    new time/op    delta
Read64bitImmediate-16      479ns ±12%      74ns ± 1%  -84.62%  (p=0.008 n=5+5)
Write64BitImmediate-16     417ns ±10%      63ns ± 2%  -84.97%  (p=0.008 n=5+5)

name                    old alloc/op   new alloc/op   delta
Read64bitImmediate-16      32.0B ± 0%      8.0B ± 0%  -75.00%  (p=0.008 n=5+5)
Write64BitImmediate-16     24.0B ± 0%      8.0B ± 0%  -66.67%  (p=0.008 n=5+5)

name                    old allocs/op  new allocs/op  delta
Read64bitImmediate-16       4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.008 n=5+5)
Write64BitImmediate-16      3.00 ± 0%      1.00 ± 0%  -66.67%  (p=0.008 n=5+5)

The use of internal.DiscardZeroes{} was considered for checking for 64bit immediate has non-zero fields, but ended up being a lot slower than just including those bits in the read. The fact that it aligns with a single u32 interpretation is quite convenient. :)

asm/instruction.go Outdated Show resolved Hide resolved
@ti-mo ti-mo force-pushed the tb/insn-unmarshal branch 3 times, most recently from 1018710 to efc7fc2 Compare January 14, 2022 09:34
Copy link
Collaborator

@lmb lmb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

asm/instruction.go Outdated Show resolved Hide resolved
asm/instruction.go Show resolved Hide resolved
asm/instruction_test.go Outdated Show resolved Hide resolved
A 64-bit immediate value was chosen to test the worst-case scenario,
covering the entire function body of ins.Marshal() and Unmarshal().

Signed-off-by: Timo Beckers <timo@isovalent.com>
This patch introduces a hand-written (un)marshaler for asm.Instruction and
eliminates the struct bpfInstruction wire format. This saves on a few allocs
and shaves off about ~85% of CPU time spent (un)marshaling on my machine.

name                    old time/op    new time/op    delta
Read64bitImmediate-16      479ns ±12%      74ns ± 1%  -84.62%  (p=0.008 n=5+5)
Write64BitImmediate-16     417ns ±10%      63ns ± 2%  -84.97%  (p=0.008 n=5+5)

name                    old alloc/op   new alloc/op   delta
Read64bitImmediate-16      32.0B ± 0%      8.0B ± 0%  -75.00%  (p=0.008 n=5+5)
Write64BitImmediate-16     24.0B ± 0%      8.0B ± 0%  -66.67%  (p=0.008 n=5+5)

name                    old allocs/op  new allocs/op  delta
Read64bitImmediate-16       4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.008 n=5+5)
Write64BitImmediate-16      3.00 ± 0%      1.00 ± 0%  -66.67%  (p=0.008 n=5+5)

Signed-off-by: Timo Beckers <timo@isovalent.com>
@ti-mo ti-mo merged commit 3696093 into cilium:master Jan 14, 2022
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.

3 participants