Skip to content

perf(decode): inline hasNilCode for byte-slice reader#56

Merged
xe-nvdk merged 1 commit intov6from
perf/hasnilcode-inline
Mar 3, 2026
Merged

perf(decode): inline hasNilCode for byte-slice reader#56
xe-nvdk merged 1 commit intov6from
perf/hasnilcode-inline

Conversation

@xe-nvdk
Copy link
Member

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

Summary

  • Adds a fast path in hasNilCode that peeks directly at the byte-slice reader's underlying data when decoding via Unmarshal/ResetBytes
  • Avoids two interface method calls (ReadByte + UnreadByte) per nil check, which is called for every pointer field during struct decode

Benchmark (vs v6 baseline)

Benchmark Before After Change
StructUnmarshal 356 ns 349 ns -2.0%
StructRoundtrip 756 ns 747 ns -1.2%
MapStringString 183 ns 176 ns -3.8%
MapStringStringPtr 213 ns 207 ns -2.8%

Test plan

  • go test -count=1 ./... — all pass
  • go test -short -race -count=1 -timeout=5m ./... — no races
  • env GOOS=linux GOARCH=386 go vet ./... — cross-platform check
  • Benchmarks — improvements across decode paths

When decoding from a byte slice (Unmarshal path), peek directly at
the underlying data instead of going through two interface method
calls (ReadByte + UnreadByte). This saves ~3-7 ns per struct pointer
field decode.
@xe-nvdk xe-nvdk merged commit 5f6d4fe into v6 Mar 3, 2026
3 checks passed
@xe-nvdk xe-nvdk deleted the perf/hasnilcode-inline 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