kubernetes-sigs / kube-scheduler-wasm-extension

All the things to make the scheduler extendable with wasm.
Apache License 2.0
86 stars 17 forks source link

allocates less buffers when decoding multiple large protos #40

Closed codefromthecrypt closed 11 months ago

codefromthecrypt commented 11 months ago

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

In our TinyGo guest, we have a read buffer used for unmarshalling protos. Before this change, any time the buffer was not big enough for a proto (such as a node or pod), a new one would be re-allocated, and the old buffer subject to garbage collection.

WebAssembly memory can grow, but not shrink, so even if we do allocate a large buffer and throw it away, and it is garbage collected.. the wasm memory will stay fixed at the larger size. This change makes things more efficient by always increasing our read buffer whenever we are unmarshalling and the old one was too small.

Which issue(s) this PR fixes:

Special notes for your reviewer:

For precision, this uses benchmarks from #39 not main.

Does this PR introduce a user-facing change?

NONE

What are the benchmark results of this change?

goos: darwin
goarch: arm64
pkg: sigs.k8s.io/kube-scheduler-wasm-extension/internal/e2e
                                               │ before.txt  │              after.txt              │
                                               │   sec/op    │    sec/op     vs base               │
PluginFilter/noop-wat/params:_small-12           265.4n ± 0%   263.6n ±  0%   -0.70% (p=0.004 n=6)
PluginFilter/noop-wat/params:_real-12            269.8n ± 0%   266.6n ±  1%   -1.15% (p=0.002 n=6)
PluginFilter/noop/params:_small-12               332.6n ± 0%   328.8n ±  1%   -1.17% (p=0.002 n=6)
PluginFilter/noop/params:_real-12                336.8n ± 0%   333.6n ±  0%   -0.95% (p=0.002 n=6)
PluginFilter/test/params:_small-12               7.162µ ± 0%   7.006µ ±  2%   -2.18% (p=0.002 n=6)
PluginFilter/test/params:_real-12                120.7µ ± 0%   122.0µ ±  1%   +1.07% (p=0.002 n=6)
PluginScore/noop-wat/params:_small-12            255.9n ± 0%   253.5n ±  0%   -0.96% (p=0.002 n=6)
PluginScore/noop-wat/params:_real-12             259.7n ± 0%   258.6n ±  0%   -0.42% (p=0.006 n=6)
PluginScore/noop/params:_small-12                378.5n ± 0%   374.0n ±  0%   -1.19% (p=0.002 n=6)
PluginScore/noop/params:_real-12                 347.6n ± 0%   346.4n ±  1%        ~ (p=0.058 n=6)
PluginScore/test/params:_small-12                4.080µ ± 0%   3.776µ ±  0%   -7.46% (p=0.002 n=6)
PluginScore/test/params:_real-12                 53.66µ ± 1%   43.26µ ± 20%  -19.38% (p=0.002 n=6)
PluginFilterAndScore/noop-wat/params:_small-12   368.0n ± 2%   366.3n ±  0%        ~ (p=0.065 n=6)
PluginFilterAndScore/noop-wat/params:_real-12    372.9n ± 3%   370.9n ±  0%        ~ (p=0.061 n=6)
PluginFilterAndScore/noop/params:_small-12       568.4n ± 0%   565.8n ±  0%   -0.46% (p=0.009 n=6)
PluginFilterAndScore/noop/params:_real-12        534.4n ± 0%   533.4n ±  1%        ~ (p=1.000 n=6)
PluginFilterAndScore/test/params:_small-12       10.93µ ± 0%   10.77µ ±  3%        ~ (p=0.065 n=6)
PluginFilterAndScore/test/params:_real-12        212.9µ ± 0%   178.9µ ±  2%  -15.97% (p=0.002 n=6)
geomean                                          1.489µ        1.441µ         -3.16%
k8s-ci-robot commented 11 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: codefromthecrypt, sanposhiho

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/kubernetes-sigs/kube-scheduler-wasm-extension/blob/main/OWNERS)~~ [sanposhiho] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment