Skip to content

Conversation

@SergeiPavlov
Copy link
Collaborator

Use SortedSet<> for most typical case instead of .Distinct().OrderBy() LINQ

Copy link

@botinko botinko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious, that it's faster on dotnet 10.

@SergeiPavlov
Copy link
Collaborator Author

SergeiPavlov commented Nov 11, 2025

It's not obvious, that it's faster on dotnet 10.

SortedSet<> constructor uses Array.Sort()

OrderBy() uses QuickSort() + .Distinct() uses HashSet
Such algorithms cannot be inlined and reduced. QuickSort is recursive by its nature

  • SortedSet saves a few iterator allocations

Copy link

@snaumenko-st snaumenko-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think we should probably have a benchmark for each similar change. Otherwise it's not obvious whether it's worth optimizing or not.

Co-authored-by: Sergey Naumenko <152863015+snaumenko-st@users.noreply.github.com>
@SergeiPavlov
Copy link
Collaborator Author

SergeiPavlov commented Nov 11, 2025

But I think we should probably have a benchmark for each similar change.

Benchmarking increases development time significantly.
That is why I prefer to make changes when the advantage is logically evident

@SergeiPavlov SergeiPavlov deleted the ColumnGatherer branch November 14, 2025 07:40
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.

4 participants