circuit: reuse garble scratch buffers to cut allocations#37
Merged
Merged
Conversation
Garble allocated a fresh []ot.Label per gate table plus the wire and gate slices on every call, so a large circuit cost tens of thousands of allocations per garbling. Carve the per-gate tables from a single slab and add an optional Garbled.Release() that returns the scratch to a per-circuit sync.Pool for reuse. The Garble signature is unchanged and Release is additive: skipping it just forgoes reuse, with no behaviour change. BenchmarkGarble (10k-gate AND chain): 10008 -> 11 allocs/op.
Owner
|
Thanks for the patch, merged it to master. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Circuit.Garbleallocates a fresh[]ot.Labelfor every gate's garbledtable, plus the wire and gate slices, on each call. For a large circuit
that's tens of thousands of allocations per garbling, which turns into real
GC pressure when garbling many circuits or the same circuit repeatedly.
This carves the per-gate tables out of a single backing slab, and adds an
optional
Garbled.Release()that returns the scratch to async.Poolforreuse. The pool is stored on the
Circuit, so it lives and dies with it.Garble's signature is unchanged andRelease()is purely additive —existing callers keep working, and skipping
Release()just forgoes thereuse with no behavioural change.
Benchmark
10,000-gate AND chain (
BenchmarkGarble, included):Release)Release(reuse)BenchmarkGarblecallsGarblewithoutRelease, so it runs on the currentcode as well — the allocation drop is reproducible directly by checking out
this branch's parent.
BenchmarkGarbleReuseshows the steady-state pooledpath.