fit icon indicating copy to clipboard operation
fit copied to clipboard

feat: decoder preallocate messages

Open muktihari opened this issue 4 months ago • 2 comments

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.

muktihari avatar Oct 12 '24 20:10 muktihari