Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sysenc: cache size of structs when finding size of slice of structs
In the current Go binary.Size() implementation, the size of struct types are cached to prevent subsequent reflect based encoding for the same types over and over again but aren't cached when encoding slices of structs. There is an allocation everytime when finding the size of structs. See golang/go#2320. goos: darwin goarch: arm64 pkg: github.com/cilium/ebpf/internal/sysenc │ unmarshal_old.txt │ unmarshal_new.txt │ │ sec/op │ sec/op vs base │ Unmarshal/[]sysenc.explicitPad-8 59.04n ± 0% 39.86n ± 0% -32.49% (p=0.000 n=10) Unmarshal/[]sysenc.explicitPad#01-8 59.93n ± 1% 40.83n ± 8% -31.88% (p=0.000 n=10) Unmarshal/[]sysenc.explicitPad#02-8 59.70n ± 0% 40.25n ± 1% -32.58% (p=0.000 n=10) Unmarshal/[]sysenc.struc-8 77.95n ± 0% 41.12n ± 0% -47.25% (p=0.000 n=10) Unmarshal/[]sysenc.struc#01-8 169.70n ± 0% 87.14n ± 1% -48.65% (p=0.000 n=10) Unmarshal/[]sysenc.struc#02-8 197.8n ± 0% 116.5n ± 0% -41.08% (p=0.000 n=10) │ unmarshal_old.txt │ unmarshal_new.txt │ │ B/op │ B/op vs base │ Unmarshal/[]sysenc.explicitPad-8 8.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Unmarshal/[]sysenc.explicitPad#01-8 8.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Unmarshal/[]sysenc.explicitPad#02-8 8.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Unmarshal/[]sysenc.struc-8 16.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10) Unmarshal/[]sysenc.struc#01-8 48.00 ± 0% 16.00 ± 0% -66.67% (p=0.000 n=10) Unmarshal/[]sysenc.struc#02-8 56.00 ± 0% 24.00 ± 0% -57.14% (p=0.000 n=10) │ unmarshal_old.txt │ unmarshal_new.txt │ │ allocs/op │ allocs/op vs base │ Unmarshal/[]sysenc.explicitPad-8 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Unmarshal/[]sysenc.explicitPad#01-8 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Unmarshal/[]sysenc.explicitPad#02-8 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Unmarshal/[]sysenc.struc-8 2.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Unmarshal/[]sysenc.struc#01-8 5.000 ± 0% 1.000 ± 0% -80.00% (p=0.000 n=10) Unmarshal/[]sysenc.struc#02-8 5.000 ± 0% 1.000 ± 0% -80.00% (p=0.000 n=10) goos: darwin goarch: arm64 pkg: github.com/cilium/ebpf/internal/sysenc │ marshal_old.txt │ marshal_new.txt │ │ sec/op │ sec/op vs base │ Marshal/[]sysenc.explicitPad-8 59.46n ± 0% 39.74n ± 0% -33.16% (p=0.000 n=10) Marshal/[]sysenc.explicitPad#01-8 59.85n ± 46% 40.15n ± 1% -32.92% (p=0.000 n=10) Marshal/[]sysenc.explicitPad#02-8 59.47n ± 2% 40.10n ± 1% -32.57% (p=0.000 n=10) Marshal/[]sysenc.struc-8 78.43n ± 1% 40.93n ± 0% -47.81% (p=0.000 n=10) Marshal/[]sysenc.struc#01-8 176.25n ± 1% 95.80n ± 0% -45.64% (p=0.000 n=10) Marshal/[]sysenc.struc#02-8 205.8n ± 0% 123.2n ± 2% -40.14% (p=0.000 n=10) │ marshal_old.txt │ marshal_new.txt │ │ B/op │ B/op vs base │ Marshal/[]sysenc.explicitPad-8 8.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Marshal/[]sysenc.explicitPad#01-8 8.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Marshal/[]sysenc.explicitPad#02-8 8.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Marshal/[]sysenc.struc-8 16.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10) Marshal/[]sysenc.struc#01-8 64.00 ± 0% 32.00 ± 0% -50.00% (p=0.000 n=10) Marshal/[]sysenc.struc#02-8 80.00 ± 0% 48.00 ± 0% -40.00% (p=0.000 n=10) │ marshal_old.txt │ marshal_new.txt │ │ allocs/op │ allocs/op vs base │ Marshal/[]sysenc.explicitPad-8 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Marshal/[]sysenc.explicitPad#01-8 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Marshal/[]sysenc.explicitPad#02-8 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Marshal/[]sysenc.struc-8 2.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) Marshal/[]sysenc.struc#01-8 6.000 ± 0% 2.000 ± 0% -66.67% (p=0.000 n=10) Marshal/[]sysenc.struc#02-8 6.000 ± 0% 2.000 ± 0% -66.67% (p=0.000 n=10) Signed-off-by: kwakubiney <kebiney@hotmail.com>
- Loading branch information