Fix data_table sort performance#14262
Conversation
Co-authored-by: Mateusz Paprocki <mattpap@gmail.com>
|
I'm not aware of the bokeh internals and where the argsort function is used, so this question may be irrelevant. But argsort only considers number arrays currently. Do you also allow sorting table columns of strings? And would it then not work because of |
|
@hageldave It's not used at all currently. I added to use in this PR before realizing an explicit reverse-lookup was needed instead, due to the possibility of CDS views. But since it is very tiny and already includes tests, I decided to leave it in case its useful in the future to have a numeric argsort. If we were ever to need an argsort for more types we would need to generalize it, but no need to bother until a need is demonstrated. |
* add argsort function to BokehJS * use argsort on table index once for comparator * construct explicit lookup to accommodate views * Apply suggestions from code review Co-authored-by: Mateusz Paprocki <mattpap@gmail.com> --------- Co-authored-by: Mateusz Paprocki <mattpap@gmail.com>
* add argsort function to BokehJS * use argsort on table index once for comparator * construct explicit lookup to accommodate views * Apply suggestions from code review Co-authored-by: Mateusz Paprocki <mattpap@gmail.com> --------- Co-authored-by: Mateusz Paprocki <mattpap@gmail.com>
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR removes unnecessary array scans in a tight inner loop that introduced quadratic runtime behavior for table sorts.
Here is a chrome profile showing that a sort on the OP code with N=500000 now takes ~1s.
I do actually wonder if
getRecordscould be improved, and also wonder whysortis called so many times for a single click. But I don't think it is worth investing much more effort until/unless we do an actual top-to-bottom evaluation of our slickgrid usage wrt to current best practices.Update
OK
argsortis not quite the right solution here in general since in the presence of CDS views the indices may not be contiguous. I am beginning to see why I did things the way I did in 2017, even though I was surely aware ofargsortat the time. However, I think constructing a manual reverse lookup will do just as well. @mattpap if there's any better typescript way to write this please let me know. I have gone ahead and left theargsortutil since it is tiny and has tests and may be useful somewhere.