python-fitparse icon indicating copy to clipboard operation
python-fitparse copied to clipboard

RecordBase.__init__ slows down

Open xmedeko opened this issue 7 years ago • 1 comments

fitparse uses many many objects and many of them are of RecordBase, The RecordBase.__init__ is a bit slow. E.g. I've tried to optimize FieldData.__init__:

     def __init__(self, field_def = None, field= None, parent_field= None, value= None, raw_value= None, units= None):
        self.field_def = field_def
        self.field = field
        self.parent_field = parent_field
        self.value = value
        self.raw_value = raw_value
        self.units = units
        ...

And parsing of event_timestamp.fit has sped up by 0.8 sec. Generally, the getattr, hasattr and setattr slows down the process when used so extensively.

I may create PR to change all RecordBase and descendants init. But there's a remark in the records.py:

    # TODO: switch back to namedtuple, and don't use default arguments as None
    #       and see if that gives us any performance improvements

Note: Also, the processor.py uses getattr, extensivelly.

xmedeko avatar Mar 06 '18 21:03 xmedeko

Thanks for noting the comment and letting us know. Of course a PR would be welcome! :)

dtcooper avatar Mar 06 '18 21:03 dtcooper