Skip to content

perf(decode): pool rec buffer in unmarshalValue#55

Merged
xe-nvdk merged 1 commit intov6from
perf/unmarshal-rec-buffer
Mar 3, 2026
Merged

perf(decode): pool rec buffer in unmarshalValue#55
xe-nvdk merged 1 commit intov6from
perf/unmarshal-rec-buffer

Conversation

@xe-nvdk
Copy link
Member

@xe-nvdk xe-nvdk commented Mar 3, 2026

Summary

  • Pools the []byte recording buffer used by unmarshalValue via sync.Pool
  • Eliminates 1 allocation per Unmarshaler.UnmarshalMsgpack decode call
  • Oversized buffers (>4KB) are dropped to prevent unbounded pool growth
  • DecodeRaw is not pooled since the caller owns the returned RawMessage slice

Benchmark (no regression; Unmarshaler alloc savings not measured by existing benchmarks)

Benchmark ns/op B/op allocs/op
StructMarshal 389 1224 4
StructUnmarshal 356 48 7
MapStringString 183 16 4
MapStringInterface 396 402 12

Test plan

  • go test -count=1 ./... — all pass
  • go test -short -race -count=1 -timeout=5m ./... — no races
  • Benchmarks — no regressions

Replaces per-call make([]byte, 0, 64) with a sync.Pool of reusable
recording buffers in unmarshalValue. Eliminates 1 alloc per
Unmarshaler.UnmarshalMsgpack call. Oversized buffers (>4KB) are
dropped to prevent unbounded pool growth.

DecodeRaw is not pooled because the caller owns the returned slice.
@xe-nvdk xe-nvdk merged commit ba9f557 into v6 Mar 3, 2026
3 checks passed
@xe-nvdk xe-nvdk deleted the perf/unmarshal-rec-buffer branch March 3, 2026 01:44
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.

1 participant