-
Notifications
You must be signed in to change notification settings - Fork 63
[JavaCallableWrappers] Parallel.ForEach per assembly #365
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
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.
jonpryor
left a comment
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:
GetJavaTypesInParallelso thecaller can opt-in to this
cacheinDirectoryAssemblyResolverneeds to now be aConcurrentDictionaryjavaTypesreturned byJavaTypeScannerneeds to alsouse a
BlockingCollectionxamarin-android, we need to make sureGenerateJavaStubsis 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
GenerateJavaStubsMSBuild task:
So we have close to a 500ms improvement for
GenerateJavaStubsinthis 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