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
[Xamarin.Android.Build.Tasks] simplify LINQ in ResolveAssemblies (#2168)
Looking at the `<ResolveAssemblies/>` task, I noticed a lot of LINQ
usage that could be simplified. We were using `HashSet<string>` that
contains a list of all assemblies, and the following code:
if (!topLevel && assemblies.All (a => new AssemblyNameDefinition (a, null).Name != assembly.Name.Name))
assemblies.Add (fullPath);
This was called from a *recursive* function and needlessly calls
`new AssemblyNameDefinition().Name` for every other assembly...
Roughly an O(N^2) operation.
So I changed the `HashSet<string>` to be a
`Dictionary<string, string>`, where the "key" is the
`assembly.Name.Name` and the value the full path to the assembly.
I also fixed up usage of `assembly.MainModule.FullyQualifiedName`,
which was deprecated; `FileName` should be used instead.
Lastly, I fixed up several LINQ expressions on the `[Output]`s of
`<ResolveAssemblies/>`. I rewrote them to use a single `foreach`
loop instead of the equivalent LINQ that would loop over the list
multiple times.
~~ Results ~~
The build time improvements here were "not zero", but also not huge.
Testing the `tests/Xamarin.Forms-Performance-Integration` project, a
build with no changes...
Before:
188 ms ResolveAssemblies 1 calls
After:
181 ms ResolveAssemblies 1 calls
I think this change is still worthwhile, since:
- The code is a bit cleaner, less LINQ for others to profile/look
at, and I plan to refactor this task more soon.
- The time savings is part of the dev-loop, and even builds with no
changes.
- There should be overall less allocations.
Other changes:
- Removed extraneous log messages for inputs/outputs.
0 commit comments