You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Java.Interop.Tools.JavaCallableWrappers] use less System.Linq for CAs (#1072)
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, saves about ~34ms for incremental builds of the
.NET podcast app.
Copy file name to clipboardExpand all lines: src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs
0 commit comments