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

Change inliner estimate code size heuristic #20904

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vijaysun-omr
Copy link
Contributor

@vijaysun-omr vijaysun-omr commented Jan 9, 2025

During the inlining optimization, there is a phase named estimate code size, that essentially collects the methods in the call graph of the top level callee that ought to be inlined. This estimation has a size threshold that limits the size of the call graph that will be analyzed, in order to prevent the estimation from taking too much cpu and memory. As per the original implementation, if the estimation looked at a call graph that has bytecodes that add up to more than the size threshold, this would cause the top level callee to not be inlined.

However, there was a "backtracking" mechanism added subsequently (still many years ago), that allowed us to skip over some very large parts of the call graph after estimating it, i.e. skip that part of the call graph from what gets considered for inlining. This allows the estimation to consider some other parts of the call graph that normally won't have been considered, and subsequently cause those other parts of the call graph to potentially get inlined.

This backtracking mechanism during estimation can cause a lot more (in one case we were running, it was an order of magnitude more) code to be estimated, but only a fraction of that code gets inlined in the end. In this PR, we are aiming to cap the amount of code that can be estimated, without hampering how much gets inlined in the end. So, this PR should save on the amount of cpu and memory taken by the estimation logic in some cases with very large call graphs that were also backtracking a lot.

Added a new env var TR_AnalyzedAllowanceFactor that allows a user to specify the factor by which we multiply the original
estimate size threshold to control how much we can analyze even with backtracking.

Added a new env var TR_GraceInliningThreshold that controls how big a callee is allowed to be, in order to be inlined even if the call graph size estimate exceeds the threshold.

@vijaysun-omr vijaysun-omr force-pushed the estimate-changes1 branch 6 times, most recently from 1e3bb08 to 97abe2e Compare January 15, 2025 17:58
@vijaysun-omr
Copy link
Contributor Author

Performance testing has shown no harmful effects of this change in other cases, and it does clearly help the test case that was estimating an order of magnitude more than it inlined. So I am taking the WIP off.

@vijaysun-omr vijaysun-omr changed the title WIP : Change inliner estimate code size heuristic Change inliner estimate code size heuristic Jan 17, 2025
@vijaysun-omr
Copy link
Contributor Author

@mpirvu and @gita-omr I would appreciate your review

Copy link
Contributor

@mpirvu mpirvu left a comment

Choose a reason for hiding this comment

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

Looks good to me.
Perhaps it's worth mentioning about the two new env vars in the description of the PR, which can serve as documentation.

if (inlineAnyway && !calleeHasNonColdCalls)
{
_optimisticSize = origOptimisticSize;
// This resetting is probably needed n this path since we are inlining despite exceeding some condition/threshold
Copy link
Contributor

Choose a reason for hiding this comment

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

Small typo: n --> on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks

@mpirvu mpirvu self-assigned this Jan 17, 2025
Do not reset the _analyzedSize value if there was a large callee
or there was estimation failure for some other reason.
Keep track of all the code we have analyzed (including code that
we estimated and then discarded) so that we do not have an
undefined amount of estimating on a given top level callee.
Introduce an "allowance" factor that gets applied on the
size threshold to separate how much we are allowed to analyze
and how much we are allowed to bring in as inlined call graph.
This commit should limit the amount of code we are allowed to
analyze to be a factor no more than 2x of what we we are allowed
to bring in to the compiled method via inlining.

Added a new env var TR_AnalyzedAllowanceFactor that allows a
user to specify the factor by which we multiply the original
estimate size threshold to control how much we can analyze
even with backtracking.

Added a new env var TR_GraceInliningThreshold that controls
how big a callee is allowed to be, in order to be inlined even
if the call graph size estimate is exceeded.

Misc. cleanups:
Fixed an inconsistency in how we reset variables during backtracking
Renamed _optimisticSize to _analyzedSize since it is less confusing
Fixed a typo in a variable name
Fixed some white spaces

Signed-off-by: Vijay Sundaresan <[email protected]>
@vijaysun-omr
Copy link
Contributor Author

Perhaps it's worth mentioning about the two new env vars in the description of the PR, which can serve as documentation.

I have added the description, thanks

@mpirvu
Copy link
Contributor

mpirvu commented Jan 18, 2025

jenkins test sanity all jdk21

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

Successfully merging this pull request may close these issues.

2 participants