Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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.
- Loading branch information