perf(Core): Avoid boxing tuple comparisons - #879
Merged
Conversation
Contributor
Author
Numpsy
marked this pull request as draft
August 3, 2026 11:32
Collaborator
|
Looks great indeed, @webwarrior-ws can you review? |
Contributor
|
Makes sense. It's strange that F# compiler didn't optimize away tuple allocations here. |
The existing tuple comparison code 1) Allocates large numbers of reference tuples 2) Uses boxing comparisons which allocate large numbers of integers Explicitly using struct tuples and CompareTo avoids all of these allocations. Benchmarks before, using the extended set of selfcheck rules | Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated | |--------------- |--------:|---------:|---------:|-----------:|-----------:|----------:|----------:| | LintParsedFile | 1.402 s | 0.0123 s | 0.0109 s | 31000.0000 | 10000.0000 | 2000.0000 | 518.02 MB | After | Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated | |--------------- |--------:|---------:|---------:|-----------:|----------:|----------:|----------:| | LintParsedFile | 1.282 s | 0.0041 s | 0.0032 s | 15000.0000 | 6000.0000 | 2000.0000 | 263.96 MB |
Contributor
Author
I had thought that the memory optimization features in .NET 9 that automatically convert local allocations to stack allocations might apply here, but it seems not (and running the benchmarks on .NET 10 or the 11 preview doesn't either). Maybe pushing the tuples through IComparer as Object means it can't, I'm not sure. |
Numpsy
marked this pull request as ready for review
August 4, 2026 21:09
This was referenced Aug 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


…stead of >=
The existing code appears to be using boxing comparisons which generate massive amounts of allocations. Changing it to use struct tuples and CompareTo avoids that, giving a large drop in allocations and a measurable performance gain.