Commit f7769ef
[Xamarin.Android.Build.Tasks] more ConvertResourcesCases improvements (#2328)
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:
.\bin\Debug\bin\xabuild.exe .\tests\Xamarin.Forms-Performance-Integration\Droid\Xamarin.Forms.Performance.Integration.Droid.csproj /v:quiet
This seemed to have a lot of useful information, and I quickly noticed:
Monodroid.AndroidResource.UpdateXmlResource -> 3683 calls -> 2.13s
..
Monodroid.AndroidResource.ResourceNeedsToBeLowerCased -> 2384 calls - 319.53ms
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:
- A `Regex` in `AndroidResource` was not using `RegexOptions.Compiled`
- There was a string append `dirPrefix + "*"` in a LINQ expression
that could be done up front.
- There was a bit of LINQ usage such as:
if (Directory.EnumerateDirectories (resourceBasePath, dirPrefix + "*").Any (dir => Directory.EnumerateFiles (dir, fileNamePattern).Any ()))
So I added `RegexOptions.Compiled` and converted the LINQ expressions
to `foreach` loops. I could see a noticeable change in these methods
which 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:
7224 ms ConvertResourcesCases 6 calls
After:
7034 ms ConvertResourcesCases 6 calls
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 safely
ignored)
Other changes:
- Code such as `(value ?? String.Empty).Trim ();`
- Simplified to `value?.Trim ();`
- Removed unused `filePath` variable
Future changes:
It may be worth auditing all regexes and adding
`RegexOptions.Compiled` if they appear to be called a lot?1 parent fa57aa8 commit f7769ef
File tree
1 file changed
+20
-13
lines changed- src/Xamarin.Android.Build.Tasks/Utilities
1 file changed
+20
-13
lines changedLines changed: 20 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
108 | | - | |
| 107 | + | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
113 | | - | |
| 112 | + | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
122 | 121 | | |
123 | 122 | | |
124 | 123 | | |
125 | 124 | | |
126 | 125 | | |
127 | 126 | | |
128 | | - | |
| 127 | + | |
129 | 128 | | |
130 | 129 | | |
131 | | - | |
132 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
139 | 146 | | |
140 | 147 | | |
141 | 148 | | |
| |||
0 commit comments