-
Notifications
You must be signed in to change notification settings - Fork 53
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
[JavaCallableWrappers] Parallel.ForEach per assembly #365
[JavaCallableWrappers] Parallel.ForEach per assembly #365
Conversation
Build logs of these changes: GenerateJavaStubs.zip |
var javaTypes = new BlockingCollection<TypeDefinition> (); | ||
|
||
Parallel.ForEach (assemblies, assembly => { | ||
var assm = resolver.GetAssembly (assembly); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. Nopity nopity not going to do it NOPE.
Cecil isn't thread safe. This cannot work. See also: b1667a2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm b1667a2, looks like it is parallelizing on the TypeDefinition
and this is doing a Task
per AssemblyDefinition
.
Let me try writing a test like you have here, and see what happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cecil isn't thread safe. This cannot work. See also: b1667a2.
I don't believe that it is possible to do what you want to do.
Since we are looking at every type in each assembly, we can parallelize this work to make things a bit faster. However, there are a few concerns when doing this: - Made sure to add a *new* method `GetJavaTypesInParallel` so the caller can opt-in to this - The `cache` in `DirectoryAssemblyResolver` needs to now be a `ConcurrentDictionary` - The list of `javaTypes` returned by `JavaTypeScanner` needs to also use a `BlockingCollection` - Downstream in `xamarin-android`, we need to make sure `GenerateJavaStubs` is now an `AsyncTask`, so the "thread safe" logger methods are used. To time the improvements, I used this project in Xamarin.Forms: https://github.com/xamarin/Xamarin.Forms/tree/master/Xamarin.Forms.ControlGallery.Android Before I did anything, the times were: 2594 ms GenerateJavaStubs 2 calls After making things parallel: 2143 ms GenerateJavaStubs 2 calls And then after a few more LINQ improvements in the `GenerateJavaStubs` MSBuild task: 2104 ms GenerateJavaStubs 2 calls So we have close to a 500ms improvement for `GenerateJavaStubs` in this project, that will build a library project + application project. To see the full changes required downstream in `xamarin-android`: dotnet/android@master...jonathanpeppers:generatejavastubs-perf
Test fails with: Expected: 6959 But was: 6958 So we should abandon this... 😢
b012118
to
bf0b5a0
Compare
See bf0b5a0, an adventure in showing the issue with this idea... |
Since we are looking at every type in each assembly, we can
parallelize this work to make things a bit faster.
However, there are a few concerns when doing this:
GetJavaTypesInParallel
so thecaller can opt-in to this
cache
inDirectoryAssemblyResolver
needs to now be aConcurrentDictionary
javaTypes
returned byJavaTypeScanner
needs to alsouse a
BlockingCollection
xamarin-android
, we need to make sureGenerateJavaStubs
is now anAsyncTask
, so the "thread safe"logger methods are used.
To time the improvements, I used this project in Xamarin.Forms:
https://github.com/xamarin/Xamarin.Forms/tree/master/Xamarin.Forms.ControlGallery.Android
Before I did anything, the times were:
After making things parallel:
And then after a few more LINQ improvements in the
GenerateJavaStubs
MSBuild task:
So we have close to a 500ms improvement for
GenerateJavaStubs
inthis project, that will build a library project + application project.
To see the full changes required downstream in
xamarin-android
:dotnet/android@master...jonathanpeppers:generatejavastubs-perf