Commit 1366d99
authored
[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.1 parent bde306d commit 1366d99
File tree
3 files changed
+36
-17
lines changed- src
- Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil
- Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers
- Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings
3 files changed
+36
-17
lines changedLines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
16 | 28 | | |
17 | 29 | | |
18 | 30 | | |
| |||
Lines changed: 7 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
209 | | - | |
| 208 | + | |
| 209 | + | |
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
281 | | - | |
282 | | - | |
| 281 | + | |
| 282 | + | |
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
346 | | - | |
| 345 | + | |
347 | 346 | | |
348 | 347 | | |
349 | 348 | | |
| |||
Lines changed: 17 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
710 | 710 | | |
711 | 711 | | |
712 | 712 | | |
713 | | - | |
714 | | - | |
715 | | - | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
716 | 718 | | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
723 | 731 | | |
724 | 732 | | |
725 | 733 | | |
| |||
0 commit comments