Skip to content

perf(sorting): Sorting performance optimizations #16062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

mddragnev
Copy link
Member

@mddragnev mddragnev commented Jul 21, 2025

Improvements so far:

  • Improved sorting algorithm using Schwartizian tranformation
  • Refactor multi-sorting algorithm to be iterative
    - making it faster, easier to read and maintain
  • Will not use Intl.collator because it gives around 300ms overhead of the algorithm runtime (Tested for 1 million records)

Sorting improvement timings of 1 million records

  1. Single column sort [type:string] - from 3.38s to 0.42s (87% faster)
  2. Single column sort [type:number] - from 1.5s to 0.31s (79% faster)
  3. Multi column sort of two columns [type:string then type:number] - from 3.88s to 0.57s (85% faster)

NOTE:
Currently, multiple sorting takes (numberOfColumns * sortingTime of 1 column) time because each expression/column can have different sorting strategies. Thus, there is no possiblity to sort all the data with all expressions in a single pass. (There might be a way to handle the case where there are no strategy in the expressions and sort the data in a single pass which will improve the algorithm for most of the cases)

Additional information (check all that apply):

  • Bug fix
  • New functionality
  • Documentation
  • Demos
  • CI/CD

Checklist:

  • All relevant tags have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them

@mddragnev mddragnev marked this pull request as ready for review July 21, 2025 15:43
@mddragnev mddragnev marked this pull request as draft July 21, 2025 15:43
@mddragnev mddragnev requested a review from rkaraivanov July 24, 2025 10:47
@mddragnev mddragnev marked this pull request as ready for review July 24, 2025 12:25
@rkaraivanov rkaraivanov merged commit 2afc1f6 into rkaraivanov/performance-measure-service Jul 29, 2025
@rkaraivanov rkaraivanov deleted the mdragnev/sorting-optimization branch July 29, 2025 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants