We need to stop doing scanning work in GetStaticDependencies of MethodBodyNode. Instead, introduce a new method (e.g. ComputeDependencies) that computes the dependencies and stores them in a DependencyList-typed field.
This is the method we're going to call in parallel.
GetStaticDependencies will be changed to just return the value of the DependencyList-typed field.
StaticDependenciesAreComputed will be changed to return whether the DependencyList is non-null.
In the Trimmer class:
Install a ComputeDependencyRoutine callback (e.g. analyzer.ComputeDependencyRoutine += ComputeDependencyNodeDependencies;)
This is the callback we'll get with a list of all the nodes that reported StaticDependenciesAreComputed == false. Make it so that we scan all the method bodies in this list in parallel (e.g. with a Parallell.ForEach).
For inspiration, this is where crossgen2 does it, but ours can be much simpler (ignore all those "deferred phase stuff, etc. - we really just want a parallel foreach with a call to scan the method for each element of the list provided as an argument):
Please make it possible to run this still singlethreaded (same as crossgen2), because debugging a multithreaded app is a pain (breakpoints hit in all threads).
In
MethodBodyNode
class:GetStaticDependencies
ofMethodBodyNode
. Instead, introduce a new method (e.g.ComputeDependencies
) that computes the dependencies and stores them in aDependencyList
-typed field.GetStaticDependencies
will be changed to just return the value of theDependencyList
-typed field.StaticDependenciesAreComputed
will be changed to return whether the DependencyList is non-null.In the
Trimmer
class:analyzer.ComputeDependencyRoutine += ComputeDependencyNodeDependencies;
)StaticDependenciesAreComputed == false
. Make it so that we scan all the method bodies in this list in parallel (e.g. with aParallell.ForEach
).For inspiration, this is where crossgen2 does it, but ours can be much simpler (ignore all those "deferred phase stuff, etc. - we really just want a parallel foreach with a call to scan the method for each element of the list provided as an argument):
https://github.com/MichalStrehovsky/iltrim/blob/4063c2e7929f41faf2b568ed1999f5e1823358df/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs#L550-L639
Please make it possible to run this still singlethreaded (same as crossgen2), because debugging a multithreaded app is a pain (breakpoints hit in all threads).