jieter / django-tables2

django-tables2 - An app for creating HTML tables
https://django-tables2.readthedocs.io/en/latest/
Other
1.9k stars 428 forks source link

TableListData sorting performance #651

Open Alex-Sichkar opened 5 years ago

Alex-Sichkar commented 5 years ago

I have a list with about 1000 objects and sort them by attribute that returns a tuple of some data. Sorting by that attribute takes about 100ms. If I sort the list myself like:

data.sort(key=lambda x: x.someattr)

it takes about 25ms. As I understand overhead happens because django-table2 wraps each object in Comparator class. Some info about it: https://stackoverflow.com/questions/34455594/why-is-sorting-a-python-list-of-tuples-faster-when-i-explicitly-provide-the-key

jieter commented 5 years ago

@ygwain I did not write the sorting logic of TableListData myself, so I am am not aware of the reasons for this particular implementation. You are welcome to open a PR with a better performing implementation as long as the functionality is still the same.