feat: decoder preallocate messages #493
Closed
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.
Add decode option to precalculate messages first before the actual decoding to avoid re-allocation when appending each decoded message. This is only eligible if the given io.Reader is an io.ReadSeeker and WithBroadcastOnly() is unset.
How fast it is may depends on I/O performance as we need to read the file twice, but typically, it beats the cost of re-allocation especially when the FIT file contains so many messages, e.g. more than 32k messages (I measure up to 237k messages from an ultra-cycling and ultra-run activities), the more the messages we have, the greater the benefit we'll gain. But more measurements are needed since users' cases may vary. I decide to not enable this by default since I'm not confident enough that this will cover most cases and probably leaving this as an opt-in feature is the best decision, we'll see.
This PR is open for feedback. Please feel free to share your thoughts.