You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf: use autoresearch to reduce allocations (#3225)
* Baseline - current block production performance with 100 txs
Result: {"status":"keep","allocs_per_op":81,"bytes_per_op":25934,"ns_per_op":34001}
* sync.Pool for sha256.Hash in leafHashOpt — eliminates 2 sha256.New() allocations per block
Result: {"status":"keep","allocs_per_op":79,"bytes_per_op":25697,"ns_per_op":34147}
* Unsafe reinterpret cast of Txs to [][]byte in ApplyBlock — eliminates make([][]byte, n) allocation
Result: {"status":"keep","allocs_per_op":78,"bytes_per_op":22996,"ns_per_op":33091}
* Direct pb.Data serialization in DACommitment — avoids pruned Data wrapper and txsToByteSlices allocations
Result: {"status":"keep","allocs_per_op":77,"bytes_per_op":20276,"ns_per_op":32480}
* unsafe.Slice in Data.ToProto() — eliminates txsToByteSlices [][]byte allocation
Result: {"status":"keep","allocs_per_op":74,"bytes_per_op":12192,"ns_per_op":31624}
* sync.Pool for protobuf message structs in MarshalBinary — eliminates 10 allocs per block
Replace per-call allocation of pb.Header/pb.Version/pb.Data/pb.Metadata with
sync.Pool reuse in the hot MarshalBinary path. ToProto() API is unchanged —
only MarshalBinary is affected since it consumes the result immediately.
Metrics (100_txs benchmark):
- 74 → 64 allocs/op (-13.5%)
- ~12.1 → ~11.1 KB (-8.3%)
- ~31ns flat
* pool SignedHeader.MarshalBinary — reuse pb.SignedHeader/pb.Header/pb.Signer/pb.Version
Eliminates 4 struct allocations per signed header marshal: pb.SignedHeader,
pb.Header, pb.Version, pb.Signer. These are now borrowed from sync.Pool and
returned after proto.Marshal completes.
Metrics (100_txs benchmark):
- 64 → 56 allocs/op
- ~11KB → ~10.2KB
* pool State.MarshalBinary and use it in UpdateState — saves 2 allocs per block
State.ToProto allocated pb.State + pb.Version + timestamppb.Timestamp per block.
MarshalBinary now pools those structs and returns the marshaled bytes directly.
pkg/store/batch.UpdateState switched from ToProto+proto.Marshal to MarshalBinary.
* fix lint
* remove files
* remove extra comments
* deps
* comments
* go fix
* changes++
---------
Co-authored-by: Julien Robert <julien@rbrt.fr>
0 commit comments