ixc / python-edtf

MIT License
52 stars 19 forks source link

Improve performance of EDTFField #14

Open jmurty opened 7 years ago

jmurty commented 7 years ago

The EDTFField stores parsed EDTF values as text in the underlying database, and converts this stored text value back into a python object when a model instance's data is loaded from the DB.

Unfortunately the conversion of text data into Python does a full pass through the EDTF grammar parsing process, which as noted in #11 is quite slow. This means that it is slow just to populate a model instance using an EDTFField from the database, even if that field is not used.

In anecdotal testing I have seen it take from 1/4 to 1/2 a second to load each model instance with a non-empty EDTF field from the database, which can be crippling when performing operations on many items such as listings.

To improve performance the EDTFField should probably be changed to stored pre-parsed values – as generated by the pre_save method – in the DB in a way that can be very quickly and directly converted back to Python by the from_db_value method without needing to be parsed.