Commit 743ad54
committed
feat: speed up ProtoMethods
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:
go test -bench='Pulsar' -memprofile mem.out -cpu 6 ./
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/op1 parent 760914f commit 743ad54
1 file changed
+9
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| 291 | + | |
| 292 | + | |
291 | 293 | | |
292 | 294 | | |
293 | 295 | | |
294 | 296 | | |
295 | 297 | | |
296 | 298 | | |
297 | | - | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
298 | 304 | | |
| 305 | + | |
299 | 306 | | |
300 | 307 | | |
301 | 308 | | |
302 | 309 | | |
303 | | - | |
| 310 | + | |
304 | 311 | | |
305 | 312 | | |
306 | 313 | | |
| |||
0 commit comments