Skip to content

[release/10.0] [mono][interp] Add max limit to the imported IL when inlining#122588

Merged
jeffhandley merged 1 commit intorelease/10.0from
backport/pr-121580-to-release/10.0
Jan 8, 2026
Merged

[release/10.0] [mono][interp] Add max limit to the imported IL when inlining#122588
jeffhandley merged 1 commit intorelease/10.0from
backport/pr-121580-to-release/10.0

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Dec 16, 2025

Backport of #121580 to release/10.0

/cc @BrzVlad

Customer Impact

  • Customer reported
  • Found internally

Mono interpreter didn't have a limit for stopping inlining. Huge methods calling methods that can be inlined would lead to even more code bloat. This can result in GBs of mem used for method compilation and seconds taking to compile the method, or simply an out of memory crash. Targets using mono interpreter (wasm + ios) can be impacted.

Regression

This behavior is not technically a regression, however it is more of a problem with more advanced compiler optimizations (added from NET9+), which end up using significantly more memory / processing time.

Testing

Tested on sample provided by customer.

Risk

Low. The fix just disables inlining after a certain code growth.

While we have some simple heuristics on whether we should inline a method or not, we have no limit on how many methods we can inline. So, if a method has 1000 callsites to methods that are inlineable, we will inline each one of them, significantly bloating the code. This is made worse by more advanced SSA optimizations, because the compilation time becomes very slow and uses a lot of memory.

The limit is set as a simple upper limit on the total amount of IL code being imported as part of method compilation. This is set to a generous initial value of 1MB, since local testing showed that it is still handled decently well. The largest value obtained from running System.Runtime libtests suite is 100K. A customer provided sample was hitting 8MB of imported code, which was causing GBs of mem usage and several seconds to compile the method. In the end, all this code was discarded anyway, since it was exceeding interpreter offset limits, and we had to retry compilation with inlining disabled.
@BrzVlad BrzVlad added Servicing-consider Issue for next servicing release review area-Codegen-Interpreter-mono labels Dec 16, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @BrzVlad, @kotlarmilos
See info in area-owners.md if you want to be subscribed.

@BrzVlad BrzVlad added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Dec 22, 2025
@rbhanda rbhanda added this to the 10.0.3 milestone Dec 22, 2025
@jeffhandley
Copy link
Member

/ba-g One known and unrelated failure on tvos

@jeffhandley jeffhandley merged commit 9d32e92 into release/10.0 Jan 8, 2026
74 of 79 checks passed
@jeffhandley jeffhandley deleted the backport/pr-121580-to-release/10.0 branch January 8, 2026 19:03
@github-actions github-actions bot locked and limited conversation to collaborators Feb 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants