-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Tools.ApiXmlAdjuster] Use Dictionaries for perf (#756)
The `Xamarin.Android.Tools.ApiXmlAdjuster` process builds an in-memory model of every Java type we know about, and then queries this model many times in order to ensure we can resolve every needed Java type to build a binding. The data structure of this model is: public class JavaApi { public List<JavaPackage> Packages { get; } } public class JavaPackage { public List<JavaType> Types { get; } } The model is then queried using LINQ:: // Bad var type = api.Packages.SelectMany (p => p.Types) .FirstOrDefault (t => t.Name == type_name); // Less bad var type = api.Packages.FirstOrDefault (p => p.Name == pkg_name) ?.Types.FirstOrDefault (t => t.Name == type_name); In the random GooglePlayServices package I used for testing, `JavaApi` contained 310 packages and a total of 5941 types. Repeatedly looping through them looking for the correct type takes a considerable amount of time. Instead, we can use a `Dictionary` to store packages and types keyed by name to significantly speed up type resolution: public class JavaApi { public Dictionary<string, JavaPackage> Packages { get; } } public class JavaPackage { public Dictionary<string, List<JavaType>> Types { get; } } For the GPS project, this reduced time taken considerably: | Version | Time | | ------- | ---- | | master | 9.3s | | This PR | 1.4s | The only "interesting" detail is that we can have multiple types with the same *Java* name, such as `MyInterface` and `MyInterfaceConsts`. Thus we need to use `Dictionary<string, List<JavaType>>` to ensure we collect them all.
- Loading branch information
Showing
17 changed files
with
150 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.