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.
The ProtoMethods is called for every unmarshal, which in turn allocates an protoiface.Methods. The Methods object does not refer to a partucular message object, so the allocation can be saved by one-time initialization at startup.
Found by the the alecthomas/go_serialization_benchmarks suite:
Before:
goos: darwin
goarch: arm64
pkg: github.com/alecthomas/go_serialization_benchmarks
Benchmark_Pulsar_Marshal-6 7480744 154.1 ns/op 51.57 B/serial 96 B/op 2 allocs/op
Benchmark_Pulsar_Unmarshal-6 5057922 236.9 ns/op 51.60 B/serial 256 B/op 7 allocs/op
After:
Benchmark_Pulsar_Marshal-6 7251019 153.9 ns/op 51.57 B/serial 96 B/op 2 allocs/op
Benchmark_Pulsar_Unmarshal-6 6409070 187.2 ns/op 51.63 B/serial 160 B/op 5 allocs/op
CC @tac0turtle @odeke-em