Commit c2daa9f
authored
[Java.Interop.Tools.Cecil] DirectoryAssemblyResolver & File.Exists() (#1065)
`dotnet-trace` of a `dotnet new maui` app:
dotnet trace collect --format speedscope -- C:\src\xamarin-android\bin\Release\dotnet\dotnet.exe build -bl --no-restore bar.csproj
Shows some interesting time spent in:
179.53ms java.interop.tools.cecil!Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Load(class System.String,bool)
7.89ms system.private.corelib.il!System.IO.File.Exists(class System.String)
171.63ms java.interop.tools.cecil!Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.ReadAssembly(class System.String)
24.18ms system.private.corelib.il!System.IO.File.Exists(class System.String)
For `DirectoryAssemblyResolver.Load()`, the common case is that the
files always exist, and the rare case they would be missing. Instead
of calling `File.Exists()` on every assembly, we can handle
`FileNotFoundException` and/or `DirectoryNotFoundException` and
`return null` appropriately.
For `DirectoryAssemblyResolver.ReadAssembly()` we can reorder the
check for symbol files:
bool haveDebugSymbols = loadDebugSymbols &&
(File.Exists (Path.ChangeExtension (file, ".pdb")) ||
File.Exists (file + ".mdb"));
So we check for `.pdb` files first, which should more likely exist in
modern projects. We could drop `.mdb` file checks at some point,
when this code isn't shared with classic Xamarin.Android.
Testing the changes afterward:
167.57ms java.interop.tools.cecil!Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Load(class System.String,bool)
141.56ms xamarin.android.cecil!Mono.Cecil.AssemblyDefinition.ReadAssembly(class System.String,class Mono.Cecil.ReaderParameters)
There appears to be some variance in the timing, but my rough estimate
is this saves about 15-20ms on incremental builds of `dotnet new maui`
projects. Larger projects could potentially save more.1 parent 8ab9d33 commit c2daa9f
File tree
1 file changed
+5
-5
lines changed- src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil
1 file changed
+5
-5
lines changedLines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | 127 | | |
131 | 128 | | |
132 | 129 | | |
133 | 130 | | |
134 | 131 | | |
135 | 132 | | |
136 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
148 | | - | |
| 147 | + | |
| 148 | + | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| |||
0 commit comments