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: optimize factory performance #120

Merged
merged 2 commits into from
Mar 31, 2024
Merged

perf: optimize factory performance #120

merged 2 commits into from
Mar 31, 2024

Conversation

muktihari
Copy link
Owner

  • Use [256]proto.Field in the predefined message in the factory for fast look up, this ensure O(1) look up when creating Field instead of looping to get the Field like previous version.
  • Since the predefined messages in factory is now using fixed array, the behavior of CreateMesg is slightly changed since we need to populate the slice for the returned message's fields. It will populate the data once during the first invocation, since this method is not used either by the decoder or the encoder it should be fine, method documentation is updated to make users aware about this change in case users want to use this method.
goos: darwin
goarch: amd64
pkg: github.com/muktihari/fit/decoder
cpu: Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
            old.txt                  new.txt               
            sec/op       sec/op     vs base                
Decode-4   126.4m ± 1%   108.6m ± 1%  -14.08% (p=0.000 n=10)

            old.txt                new.txt             
              B/op          B/op      vs base          
Decode-4   67.39Mi ± 0%   67.39Mi ± 0%  ~ (p=0.361 n=10)

            old.txt                new.txt             
           allocs/op    allocs/op   vs base            
Decode-4   900.0k ± 0%   900.0k ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

@muktihari muktihari added the performance Changes related to performance improvement label Mar 31, 2024
@muktihari muktihari self-assigned this Mar 31, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.02%. Comparing base (b531a82) to head (ece2daa).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #120   +/-   ##
=======================================
  Coverage   99.02%   99.02%           
=======================================
  Files          45       45           
  Lines        4396     4396           
=======================================
  Hits         4353     4353           
  Misses         43       43           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@muktihari muktihari merged commit ec7d032 into master Mar 31, 2024
1 check passed
@muktihari muktihari deleted the perf/optimize-factory branch March 31, 2024 00:22
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.

2 participants