I noticed that processing a large amount of FIT files was quite slow, so did a bit of profiling.
Using ruby-prof revealed that a lot of time was spent in Module#attr_accessor, creating the attribute accessor methods for the fields of the various data record classes.
A FIT file containing 104 Fit4Ruby::Record instances for example, would call Fit4Ruby::Record#attr_accessor 104 times for each field of that class whereas it only needs to call it once (per class, per field).
The fix is quite straightforward (see diff) and makes reading/processing FIT files almost 20% faster! :tada:
Benchmarking the processing of a directory containing 78 FIT files on the master branch and the feature branch respectively illustrates the performance improvement:
I noticed that processing a large amount of FIT files was quite slow, so did a bit of profiling.
Using
ruby-prof
revealed that a lot of time was spent inModule#attr_accessor
, creating the attribute accessor methods for the fields of the various data record classes.A FIT file containing 104
Fit4Ruby::Record
instances for example, would callFit4Ruby::Record#attr_accessor
104 times for each field of that class whereas it only needs to call it once (per class, per field).The fix is quite straightforward (see diff) and makes reading/processing FIT files almost
20%
faster! :tada:Benchmarking the processing of a directory containing
78
FIT files on the master branch and the feature branch respectively illustrates the performance improvement: