Split GetInterpThreadContext into allocating and non-allocating variants#122688
Merged
janvorli merged 1 commit intodotnet:mainfrom Jan 2, 2026
Merged
Split GetInterpThreadContext into allocating and non-allocating variants#122688janvorli merged 1 commit intodotnet:mainfrom
janvorli merged 1 commit intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @BrzVlad, @janvorli, @kg |
This ensures that InterpThreadContext is not allocated unless the interpreter is actually used. For example, TryEnsureSufficientExecutionStack allocated InterpThreadContext even when the interpreter is not used.
220ea5d to
43799fc
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request optimizes interpreter thread context allocation by splitting GetInterpThreadContext into two variants: a non-allocating getter (GetInterpThreadContext) and an allocating/creating variant (GetOrCreateInterpThreadContext). This ensures that InterpThreadContext is only allocated when the interpreter is actually used, avoiding unnecessary allocations in scenarios like TryEnsureSufficientExecutionStack.
Key Changes
- Added
GetOrCreateInterpThreadContext()method that allocates the context if needed - Modified
GetInterpThreadContext()to simply return the existing context (may be null) - Updated all call sites where allocation is needed to use the new
GetOrCreateInterpThreadContext() - Changed memory allocation from
malloc/freetonew/deletefor consistency - Moved interpreter context cleanup in
OnThreadTerminateafter the shutdown check
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/threads.h | Added declaration for GetOrCreateInterpThreadContext() |
| src/coreclr/vm/threads.cpp | Implemented split methods with appropriate contracts; moved cleanup code |
| src/coreclr/vm/prestub.cpp | Updated local helper to use allocating variant |
| src/coreclr/vm/interpexec.cpp | Changed to use allocating variant and switched to new/delete |
| src/coreclr/vm/eetwain.cpp | Removed null checks that are now potentially problematic |
Member
Author
|
Related to #122404 |
BrzVlad
approved these changes
Dec 22, 2025
This was referenced Jan 9, 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 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.
This ensures that InterpThreadContext is not allocated unless the interpreter is actually used. For example, TryEnsureSufficientExecutionStack allocated InterpThreadContext even when the interpreter is not used.