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

Add background type preloading based on multicorejit #52595

Merged
merged 3 commits into from
Jun 4, 2021

Conversation

gbalykov
Copy link
Member

@gbalykov gbalykov commented May 11, 2021

This is a second part of #48326 change, which enables handling of methods loaded from r2r images. Background thread of multicorejit now not only jits methods but also loads methods from R2R images. This allows to load types in background thread.

This is required as part of #45748 change (specifically, #45748 (comment)), goal of which is to enable background type preloading using multicorejit.

On tizen armel, on xamarin calculator app next improvement is achieved:

commit startup time, s
6.0 base (98c45ff) 2.2478
6.0 base + #48326 1.844 (-18.0%)
6.0 base + this PR 1.7499 (-22.2%)

cc @alpencolt

@gbalykov
Copy link
Member Author

@noahfalk @kouvel could you, please, take a look?

@kouvel
Copy link
Member

kouvel commented May 18, 2021

cc @mangod9

Copy link
Member

@kouvel kouvel left a comment

Choose a reason for hiding this comment

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

There were some preexisting assumptions about MCJ not recording/playing methods that have pregenerated code. I have fixed a few things in #53198. Could you please incorporate the latest commit in my branch into yours?


if (m_pMulticoreJitRecorder != NULL)
{
m_pMulticoreJitRecorder->RecordMethodJit(pMethod, true, false);
Copy link
Member

Choose a reason for hiding this comment

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

I think the dojit parameter should be true here, in the sense we are recording a load of pregenerated method code, but the profile may be played back in a situation where that method is not pregenerated. The closest alternative would be to JIT the method, in effect the profile only records methods whose code should be loaded or jitted. Also, if the player does not try to compile the method, it would not actually load the pregenerated code, so it would only load the types relevant to where the method is, and would not load any other types used by the method. It may also help to parallelize the R2R method code loads.

I suggest the following:

  • Remove the dojit parameters and treat it as true
  • Remove the NO_JIT_TAG flag
  • Remove RecordMethodLoad since the dojit parameter is the only differentiating factor
  • Rename RecordMethodJit and equivalent to RecordMethodLoadOrJit or similar

@@ -45,7 +46,7 @@ const int MAX_WALKBACK = 128;

enum
{
MULTICOREJIT_PROFILE_VERSION = 102,
MULTICOREJIT_PROFILE_VERSION = 103,
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be necessary if the NO_JIT_TAG flag is removed (based on my other comment), if I understood correctly that was the only change to the storage format

{
if (MulticoreJitManager::IsMethodSupported(this))
{
mcJitManager.RecordMethodLoad(this); // Tell multi-core JIT manager to record method on successful load from R2R
Copy link
Member

Choose a reason for hiding this comment

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

In my branch I have moved this code to after a successful SetNativeCode() in the caller such that there would not be duplicate recordings of the method during multi-threaded races

@kouvel
Copy link
Member

kouvel commented May 24, 2021

With the current changes, I believe the pregenerated methods would not be loaded by MCJ and instead would be jitted. The vast majority of methods would fall into that category, so a lot more would be unnecessarily jitted compared to before. After the fixes above and after incorporating my branch, those methods should be loaded and tiered up appropriately and not jitted up-front. I'm curious to see if that makes any difference to the startup time in your app.

gbalykov and others added 3 commits June 4, 2021 16:17
…back R2R'ed code

- Renamed `*wasTier0Jit` to `wasTier0` to include pregenerated code that is loaded, which is considered tier 0
- Added a subset of `FinalizeOptimizationTierForTier0Jit` as `FinalizeOptimizationTierForTier0Load` to set the `wasTier0` flag so that those methods would be call-counted for tiering when MCJ-loaded code is used, and updated the relevant code
- Moved recording of loaded method code to after a successful `SetNativeCode()` to prevent duplicate recordings of the same method in multi-threaded races
- Enabled `MulticoreJitPrepareCodeConfig` to look up pregenerated code to parallelize that work
@gbalykov gbalykov force-pushed the multicorejit-unification-btp branch from e0d3216 to 2d7eede Compare June 4, 2021 18:05
@gbalykov
Copy link
Member Author

gbalykov commented Jun 4, 2021

@kouvel thanks for taking a look at this! Indeed, invocation of GetPrecompiledR2RCode, which loads more types related to method, improved overall speedup of this optimization:

commit startup time, s
6.0 base (911640b) 2.2881
6.0 base with mjc 1.8719 (-18.19%)
6.0 base + this PR 1.6399 (-28.33%)

I've fixed other changes as you suggested.

Copy link
Member

@kouvel kouvel left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@kouvel kouvel merged commit 951b424 into dotnet:main Jun 4, 2021
@gbalykov
Copy link
Member Author

gbalykov commented Jun 5, 2021

Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Jul 5, 2021
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.

2 participants