-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RegexOptions.Compiled impacts Android startup #71007
Comments
Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions Issue DetailsDescriptionReviewing a customer issue, we noticed usage of This was coming from the AppCenter SDK: This shows up as a regression from Xamarin.Android -> .NET 6, because The question here, is how do we get the previous behavior from mono/mono? Is there a way to toggle runtime/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs Line 105 in 807d091
If there is a way to toggle Reproduction Steps
Expected behavior
Actual behavior
Regression?From a customer's perspective they might say this is startup performance regression from Xamarin.Android to .NET 6. Known WorkaroundsDon't use ConfigurationI tested this with the .NET 6.0.400-preview.22301.10 SDK, and the SR 1 version of .NET MAUI. Other information
|
RegexOptions.Compiled is a tradeoff between startup overhead and throughput: it adds overhead to constructing the Regex in exchange for making regexes execute faster. Are you seeing this construction cost increase but throughput not also increase? If they both go up, then the opt-in flag is doing what it's supposed to do, and if a customer doesn't want to tradeoff that construction overhead for throughput, they shouldn't be setting Compiled to opt-in. (And if they want both, they should consider using the regex source generator in .NET 7 instead; this will give them both the construction perf and the throughput perf, at the expense of a bit larger IL size.) |
In this case, the customer's use of |
Just curious, why do they not pass it when targeting .NET Standard?
|
If you look at blame, it doesn't actually give much detail: microsoft/appcenter-sdk-dotnet@70f7944 I'm not sure what issue they're trying to solve here either. It seems like the old code would have worked in Xamarin.Android in 2019 to me? |
My guess is that they thought it was still broken. I think the to-do here is to just pass on Stephen's guidance. Startup time, throughput, on disk size - pick two!
Question for @steveisok I think. |
On Android, we would pretty much never want throughput for anything. So that is why the default setting might be interesting. |
Tagging subscribers to 'arch-android': @steveisok, @akoeplinger Issue DetailsDescriptionReviewing a customer issue, we noticed usage of This was coming from the AppCenter SDK in the customer's app: This shows up as a regression from Xamarin.Android -> .NET 6, because The question here, is how do we get the previous behavior from mono/mono? Is there a way to toggle runtime/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs Line 105 in 807d091
If there is a way to toggle Reproduction Steps
Expected behavior
Actual behavior
Regression?From a customer's perspective they might say this is startup performance regression from Xamarin.Android to .NET 6. Known WorkaroundsDon't use ConfigurationI tested this with the .NET 6.0.400-preview.22301.10 SDK, and the SR 1 version of .NET MAUI. Other information
|
If we were to do anything, I think it would have to be through a runtime feature switch. @jonathanpeppers, how significant are we talking vs what was in mono/mono? |
@danmoseley they are targeting .NET Standard 1.0 only, which does not have |
If you look at the PR from the commit and the linked AzDO bug you'll eventually find out that this was done to address microsoft/appcenter-sdk-dotnet#1247. I think because we didn't have the I don't think we should do anything here, the feature works as expected. AppCenter should either not pass in |
We discussed this some, and we think:
If we implement the same System.Reflection changes for Mono, we should test the impact on Android startup. Let me know if I can help with that. We can close this for now, thanks. |
Longer term it would be interesting to develop some guidance around use of the regex source generator on mobile. I guess that will emerge as folks use it. |
It appears the new https://github.com/jonathanpeppers/AndroidRegex I'm working on a blog post that will mention this in detail. |
Nice! |
@jonathanpeppers I see the flame diagram there for "before", I'm curious what the flame diagram looks like "after" (if you collected it) |
Ah yes, so I added the |
If I read right, the ctor was 174ms and IsMatch another 49ms. Now the ctor is negligible (because source gen) and IsMatch is only 6ms (because it is smarter about finding there is no possible start position, apparently) So I think I'd expect an improvement of over 200ms, not 93.5 ms? |
My general observation, is these timings are a bit slower when traced -- especially on a mobile device running Mono. Maybe @lateralusX knows if there is some amount of overhead? I normally test with & without tracing to double-check things. |
|
If you run sampling it will impact process since part of sampling includes a STW (stop the world for every sample) so it will affect timers running longer than the sample interval (1ms be default). If you don't run with sampling, the impact should be minimal. It should also be mentioned that the elapsed time in speed scope is a "calculated metric", but sampling should mainly be used in relation to the total number of samples (percent, flam graphs etc) to spot methods with most samples, that is how tools like perfview visualize sample data. If you want to measure wall clock times, you should do so by add specific trace events, use custom timers or in cases there is support for low level runtime profilers use build in method enter/leave support. |
Jupp, CompileMethod is a place holder when runtime needs to JIT compile a method. Part of JIT compile a method might results in the need to load additional types (assemblies) and potential do some other runtime work, but CompileMethod gets triggered where there is a need to JIT or load an AOT:ed method. If you run tracing with JIT/Loader events you will find what method gets JIT:ed in those events and if any additional assemblies/types needs to be loaded as part of the process. |
Description
Reviewing a customer issue, we noticed usage of
RegexOptions.Compiled
impacts startup quite a bit:This was coming from the AppCenter SDK in the customer's app:
https://github.com/microsoft/appcenter-sdk-dotnet/blob/b19ec99e16e554eb1382342b2852b16f7d8f0084/SDK/AppCenter/Microsoft.AppCenter.Shared/AppCenter.cs#L26
This shows up as a regression from Xamarin.Android -> .NET 6, because
RegexOptions.Compiled
was not implemented at all in mono/mono.The question here, is how do we get the previous behavior from mono/mono? Is there a way to toggle
RuntimeFeature.IsDynamicCodeCompiled
?runtime/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.cs
Line 105 in 807d091
If there is a way to toggle
RuntimeFeature.IsDynamicCodeCompiled
, should we consider turning on this flag by default on Android? I've found System.Reflection.Emit to be very impactful to startup.Reproduction Steps
dotnet new android
MainActivity.cs
and put_ = new Regex(@"([^;=]+)=([^;]+)(?:;\s*)?", RegexOptions.Compiled);
in theOnCreate()
method.dotnet build -c Release -t:Run
Expected behavior
RegexOptions.Compiled
doesn't have a significant impact to Android startup. (Or we have a feature flag to turn it off)Actual behavior
RegexOptions.Compiled
has a significant impact to Android startup.Regression?
From a customer's perspective they might say this is startup performance regression from Xamarin.Android to .NET 6.
Known Workarounds
Don't use
RegexOptions.Compiled
, useNormal
.Configuration
I tested this with the .NET 6.0.400-preview.22301.10 SDK, and the SR 1 version of .NET MAUI.
Other information
dotnet trace
output: regexoptions.compiled.zipThe text was updated successfully, but these errors were encountered: