perf: bsr fast paths for readCode/PeekCode + pool OmitEmpty slices#67
Merged
perf: bsr fast paths for readCode/PeekCode + pool OmitEmpty slices#67
Conversation
Three optimizations targeting decode throughput and encode GC pressure: 1. readCode() bsr fast path (#57): read directly from byte-slice data instead of going through interface dispatch on the hottest decode function. Handles d.rec recording mode inline. 2. PeekCode() bsr fast path (#59): peek directly at byte-slice data avoiding ReadByte+UnreadByte interface dispatch. 3. Pool OmitEmpty filtered field slices (#58): use sync.Pool for the []*field slice allocated when struct fields are omitted, returned via putFilteredFields after iteration in encodeStructValue. Benchmark results (Apple M3 Max, 3 iterations): StructUnmarshal: 361 ns → 334 ns (-7.5%) StructUnmarshalPartially: 247 ns → 232 ns (-6.1%) MapIntInt: 328 ns → 314 ns (-4.3%) StructManual: 569 ns → 544 ns (-4.4%) Closes #57, closes #59, closes #58
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.
Summary
Three optimizations targeting decode throughput and encode GC pressure:
[]*fieldslices allocated when struct fields are omittedBenchmark (before → after, Apple M3 Max, 3 iterations)
Test plan
go test -count=1 ./...— all passgo test -short -race -count=1 -timeout=5m ./...— no racesenv GOOS=linux GOARCH=386 go vet ./...— cross-platform checkCloses #57, closes #59, closes #58