[Xamarin.Android.Build.Tasks] more ConvertResourcesCases improvements #2328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: http://www.getcodetrack.com/
I used a "freeware" .NET profiler to see what it would turn up.
Using the tool, I profiled the following .NET process:
This seemed to have a lot of useful information, and I quickly noticed:
This is a known codepath, the
ConvertResourcesCases
MSBuild task,that we know takes a bit of time.
Looking through the call stack, I saw two points we could make easy
fixes for:
Regex
inAndroidResource
was not usingRegexOptions.Compiled
dirPrefix + "*"
in a LINQ expressionthat could be done up front.
So I added
RegexOptions.Compiled
and converted the LINQ expressionsto
foreach
loops. I could see a noticeable change in these methodswhich moved further down the list of methods, when sorted by time
duration.
But since the time differences in the profiler likely aren't going
to reflect the real world, I did a before/after comparision with the
Xamarin.Forms.ControlGallery project.
Project here:
https://github.com/jonathanpeppers/Xamarin.Forms/tree/msbuild-timing/Xamarin.Forms.ControlGallery.Android
Script here:
https://github.com/jonathanpeppers/msbuild-timing/blob/master/xamarin.forms.ps1
Before:
After:
So about a 200ms improvement on Windows, for adjusting a bit of code.
I suspect the improvement won't be as good on MacOS, since I don't
believe
RegexOptions.Compiled
is implemented in Mono. (It is safelyignored)
Other changes:
(value ?? String.Empty).Trim ();
value?.Trim ();
filePath
variableFuture changes:
It may be worth auditing all regexes and adding
RegexOptions.Compiled
if they appear to be called a lot?