Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve proto marshaler #60

Merged
merged 1 commit into from
Dec 21, 2023
Merged

perf: improve proto marshaler #60

merged 1 commit into from
Dec 21, 2023

Conversation

muktihari
Copy link
Owner

Context: MarshalBinary()

  • Message Definition: Reduce bytes alloc by directly append to b. For this case, there is no benefit on using sync.Pool since the bytes size is known at front, using sync.Pool will only add overhead.
  • Message: Use sync.Pool to reduce memory usage and alloc since the method might be called thousands times, there is not much different in sec/op but memory usage is way reduced
goos: darwin
goarch: amd64
pkg: github.com/muktihari/fit/proto
cpu: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
                           │   old.txt    │               new.txt                │
                           │    sec/op    │    sec/op     vs base                │
MarshalMessageDefinition-4   731.2n ± 39%   242.2n ± 77%  -66.88% (p=0.000 n=10)
MarshalMessage-4             2.913µ ± 25%   2.724µ ± 23%        ~ (p=0.123 n=10)
geomean                      1.459µ         812.1n        -44.35%

                           │  old.txt   │               new.txt                │
                           │    B/op    │    B/op     vs base                  │
MarshalMessageDefinition-4   290.0 ± 0%   290.0 ± 0%        ~ (p=1.000 n=10) ¹
MarshalMessage-4             628.0 ± 0%   180.0 ± 0%  -71.34% (p=0.000 n=10)
geomean                      426.8        228.5       -46.46%
¹ all samples are equal

                           │  old.txt   │               new.txt               │
                           │ allocs/op  │ allocs/op   vs base                 │
MarshalMessageDefinition-4   2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=10) ¹
MarshalMessage-4             81.00 ± 0%   78.00 ± 0%  -3.70% (p=0.000 n=10)
geomean                      12.73        12.49       -1.87%
¹ all samples are equal

@muktihari muktihari added the performance Changes related to performance improvement label Dec 21, 2023
@muktihari muktihari self-assigned this Dec 21, 2023
@muktihari muktihari merged commit fc7ab4a into master Dec 21, 2023
1 check passed
@muktihari muktihari deleted the perf/proto-marshaler branch December 21, 2023 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Changes related to performance improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant