react-bootstrap-table2 icon indicating copy to clipboard operation
react-bootstrap-table2 copied to clipboard

Optimized string column sort (comparator + splitNested)

Open Avasam opened this issue 4 years ago • 2 comments

I've started experiencing really bad delay when changing page in my table whenever sorting by a string value column. I found the splitNested function to be the culprit. See 2 perf screenshots below

SplitNested is slow 1 SplitNested is slow 2

It seems to be doing some useless actions, like joining on an array of 1 string and replacing text in multiple iterations. I also did my best to optimize the regex without affecting functionality. Here are some performance comparisons from JSBench.Me: splitNested Optimisation test results

And the new real-world performance results: splitNested Optimized results

Finally, I've used a better string comparison for very large array of strings. namely Intl.Collator instead of localeCompare. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#performance (I haven't yet recorded performance comparison)

Avasam avatar May 20 '21 04:05 Avasam

Mind a review?

Avasam avatar Jul 08 '23 18:07 Avasam