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

refactor!: change decoder's listener behavior #190

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

muktihari
Copy link
Owner

Background: #182

BREAKING CHANGES:

  • By default, Decoder no longer copy the message before send it to listeners for efficiency, the lifecycle of the mesg is only guaranteed before OnMesg method returns so any listener that process the message concurrently should copy the mesg before return. For legacy behavior (<= v0.14.0), use decoder.WithBroadcastMesgCopy()

What's Changed:

  • filedef's Listener now copy the mesg before processing it concurrently to accommodate the behavior change. It copies the mesg using pool of reusable messages to reduce alloc.

Benchmark:

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                
DecodeWithFiledef-4   105.53m ± 5%   90.92m ± 10%  -13.85% (p=0.002 n=10)

                       old.txt                   new.txt                
                         B/op          B/op      vs base                
DecodeWithFiledef-4   92.47Mi ± 0%   49.77Mi ± 0%  -46.17% (p=0.000 n=10)

                       old.txt                  new.txt               
                      allocs/op    allocs/op   vs base                
DecodeWithFiledef-4   200.0k ± 0%   100.1k ± 0%  -49.95% (p=0.000 n=10)

close #182

@muktihari muktihari added enhancement New feature or request performance Changes related to performance improvement labels Apr 16, 2024
@muktihari muktihari self-assigned this Apr 16, 2024
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5503e19) to head (2992a98).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #190   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           43        43           
  Lines         3549      3576   +27     
=========================================
+ Hits          3549      3576   +27     

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

@muktihari muktihari merged commit a4c820b into master Apr 16, 2024
4 checks passed
@muktihari muktihari deleted the refactor/change-decoder-listener-behavior branch April 16, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance Changes related to performance improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

decoder: reduce alloc + copy before passing the mesg to Listener
2 participants