Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono][inline] Allow inlining methods containing ctor calls if they h… #84660

Merged
merged 1 commit into from
Apr 12, 2023

Conversation

vargaz
Copy link
Contributor

@vargaz vargaz commented Apr 11, 2023

…ave the aggressive inlining flag.

Re: dotnet/perf-autofiling-issues#15660.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 11, 2023
@ghost ghost assigned vargaz Apr 11, 2023
@lewing
Copy link
Member

lewing commented Apr 11, 2023

@vargaz vargaz added area-Codegen-AOT-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 12, 2023
@vargaz vargaz merged commit 8699942 into dotnet:main Apr 12, 2023
@vargaz vargaz deleted the inline-ctor branch April 12, 2023 03:02
Comment on lines +5853 to +5854
if (!m_method_is_aggressive_inlining (cfg->current_method) && !m_method_is_aggressive_inlining (cmethod))
INLINE_FAILURE ("ctor call");
Copy link
Member

@tannergooding tannergooding Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vargaz, why only if they are marked aggressive inlining rather than in general based on the same heuristics as other methods?

There are a lot of methods that are small and call constructors or other things that aren't marked this way that would benefit.

Consider for example op_Explicit and op_Implicit cast operators that are implemented simply as:

public static implicit operator BigInteger(byte value) => new BigInteger(value);

We likewise have constructors that defer to other constructors and similar where many of these are very small methods that basically just forward to others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mono inlining heuristics are not very good, this PR just fixes an issue where inlining was disabled even through the callee had the aggressive inlining flag.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue tracking Mono improving these heuristics?

We (the libraries team) don't typically put AggressiveInlining on small methods, particularly methods <= 16 bytes of IL -- This is the "always inline threshold" for RyuJIT, barring cases like PGO or the method always throwing, which would indicate its a likely cold path.

We instead tend to only put it on methods which are known to be extra hot or known to be problematic for the JIT, such as having a large amount of code that can be elided as part of dead code optimizations, generic specialization, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(so this may be a general place where Mono could see some easy perf wins by adjusting its heuristics and becoming more similar to what RyuJIT is doing)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its possible. In this particular case, INLINE_FAILURE means we abort inlining the current method if it makes a call to a ctor.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants