[Java.Interop.Tools.JavaCallableWrappers] use less System.Linq for CAs#1072
Merged
jonpryor merged 2 commits intodotnet:mainfrom Jan 18, 2023
Merged
Conversation
Context: https://github.com/microsoft/dotnet-podcasts/tree/net8.0 When building the .NET Podcast sample for .NET 8, profiling an incremental build with a `.xaml` change I noticed: 80.42ms java.interop.tools.javacallablewrappers!Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.IsNonStaticInnerClass(... There was a double-nested usage of System.Linq via a `GetBaseConstructors()` method, so I "unrolled" this to a plain `foreach` loop. After this change: 61.50ms java.interop.tools.javacallablewrappers!Java.Interop.Tools.TypeNameMappings.JavaNativeTypeManager.IsNonStaticInnerClass(... This made me review places using System.Linq `.Any()` calls: 59.78ms System.Linq.il!System.Linq.Enumerable.Any(class System.Collections.Generic.IEnumerable`1<!!0>) 15.87ms System.Linq.il!System.Linq.Enumerable.Any(class System.Collections.Generic.IEnumerable`1<!!0>,class System.Func`2<!!0,bool>) 1.98ms system.linq.il!System.Linq.Enumerable.Any(class System.Collections.Generic.IEnumerable`1<!!0>) Which I was able to track down to calls to an extension method like: CustomAttributeProviderRocks.GetCustomAttributes().Any() I created a new `CustomAttributeProviderRocks.AnyCustomAttributes()` extension method, which is a bit better because: * We avoid a `yield return` & related compiler machinery. * We avoid allocating custom attribute objects in some cases, as System.Linq's `Any()` will enumerate and create at least one. Before: 107.90ms java.interop.tools.cecil!Java.Interop.Tools.Cecil.CustomAttributeProviderRocks+<GetCustomAttributes>d__1.MoveNext() 3.80ms java.interop.tools.cecil!Java.Interop.Tools.Cecil.CustomAttributeProviderRocks.GetCustomAttributes(class Mono.Cecil.ICus... After: 58.58ms java.interop.tools.cecil!Java.Interop.Tools.Cecil.CustomAttributeProviderRocks.AnyCustomAttributes(class Mono.Cecil.ICustomAttributeProvider,class System.Type) 36.01ms java.interop.tools.cecil!Java.Interop.Tools.Cecil.CustomAttributeProviderRocks+<GetCustomAttributes>d__3.MoveNext() 1.97ms java.interop.tools.cecil!Java.Interop.Tools.Cecil.CustomAttributeProviderRocks.GetCustomAttributes(class Mono.Cecil.ICus... These changes are about: IsNonStaticInnerClass ~19ms faster CustomAttributeProviderRocks (Any) ~15ms faster Overall, saving about ~34ms for incremental builds of the .NET podcast app.
jonathanpeppers
commented
Jan 11, 2023
Comment on lines
+11
to
+12
| public static bool AnyCustomAttributes (this ICustomAttributeProvider item, Type attribute) => | ||
| item.AnyCustomAttributes (attribute.FullName); |
Member
Author
There was a problem hiding this comment.
I'm not completely sold on the name AnyCustomAttributes(), let me know if anyone has other ideas.
jonpryor
pushed a commit
to dotnet/android
that referenced
this pull request
Jan 24, 2023
Changes: dotnet/java-interop@cf80deb...1366d99 * dotnet/java-interop@1366d998: [Java.Interop.Tools.JavaCallableWrappers] use less System.Linq for CAs (dotnet/java-interop#1072) * dotnet/java-interop@bde306d5: [Java.Interop.Tools.JavaCallableWrappers] JavaTypeScanner.GetJavaTypes (dotnet/java-interop#1076) * dotnet/java-interop@f03088e7: [Java.Interop.Tools.JavaCallableWrappers] IMetadataResolver redux (dotnet/java-interop#1075) * dotnet/java-interop@e11d0242: [lgtm] Fix LGTM-reported issues. (dotnet/java-interop#1074) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context: https://github.com/microsoft/dotnet-podcasts/tree/net8.0
When building the .NET Podcast sample for .NET 8, profiling an incremental build with a
.xamlchange I noticed:There was a double-nested usage of System.Linq via a
GetBaseConstructors()method, so I "unrolled" this to a plainforeachloop.After this change:
This made me review places using System.Linq
.Any()calls:Which I was able to track down to calls to an extension method like:
I created a new
CustomAttributeProviderRocks.AnyCustomAttributes()extension method, which is a bit better because:We avoid a
yield return& related compiler machinery.We avoid allocating custom attribute objects in some cases, as System.Linq's
Any()will enumerate and create at least one.Before:
After:
These changes are about:
Overall, saving about ~34ms for incremental builds of the .NET podcast app.