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.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.
- Loading branch information