Uh oh!
There was an error while loading. Please reload this page.
[clr-interp] Fix performance of compiling huge methods - #119514
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
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 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
davidwrighton
commented
Sep 9, 2025
Oops, the allocation changes aren't safe. Sigh. I'll have to think on that. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…and one based on malloc/free - Fix the TArray InsertAt function
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
janvorli
left a comment
There was a problem hiding this comment.
LGTM modulo the unused local comment, thank you!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.