[clr-interp] Fix performance of compiling huge methods#119514
Merged
davidwrighton merged 2 commits intodotnet:mainfrom Sep 11, 2025
Merged
[clr-interp] Fix performance of compiling huge methods#119514davidwrighton merged 2 commits intodotnet:mainfrom
davidwrighton merged 2 commits intodotnet:mainfrom
Conversation
- Remove O(n) algorithm in InterpCompiler::EmitCodeIns which was debug only, replace with O(1) algorithm - The new conservative range computuation code also has an O(N^2) algorithm for ranges, and this is replaced with an O(n*logN) algorithm with better constant factors (Binary search in an array instead of linear scan of a linked list) - Adjust apis on TArray so that the RemoveAt and Remove functions don't re-order the array. Change the names of the existing apis to have a _ArrayIsBag suffix, and add more typical implementations of RemoveAt and InsertAt
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves the performance of compiling large methods in the CLR interpreter by addressing O(N²) and O(N) algorithmic bottlenecks in critical compilation paths.
Key changes:
- Replaces O(N) debug-only IL offset validation with O(1) hash table lookup using a side table
- Refactors conservative GC range computation from O(N²) linked list operations to O(N log N) binary search with array-based storage
- Enhances TArray class with proper order-preserving RemoveAt/InsertAt methods while renaming existing bag-style operations
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/coreclr/interpreter/datastructs.h | Adds Set method, order-preserving RemoveAt/InsertAt, and renames bag-style operations |
| src/coreclr/interpreter/compileropt.cpp | Updates method calls to use renamed bag-style array operations |
| src/coreclr/interpreter/compiler.h | Adds debug-only side table field and fixes operator formatting |
| src/coreclr/interpreter/compiler.cpp | Implements O(1) IL offset validation and O(N log N) conservative range computation |
Contributor
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
Member
Author
|
Oops, the allocation changes aren't safe. Sigh. I'll have to think on that. |
kg
reviewed
Sep 10, 2025
kg
reviewed
Sep 10, 2025
…and one based on malloc/free - Fix the TArray InsertAt function
janvorli
reviewed
Sep 11, 2025
janvorli
approved these changes
Sep 11, 2025
Member
janvorli
left a comment
There was a problem hiding this comment.
LGTM modulo the unused local comment, thank you!
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Uh oh!
There was an error while loading. Please reload this page.