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?
|
if (RuntimeFeature.IsDynamicCodeCompiled && (options & RegexOptions.Compiled) != 0) |
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
- Open
MainActivity.cs and put _ = new Regex(@"([^;=]+)=([^;]+)(?:;\s*)?", RegexOptions.Compiled); in the OnCreate() method.
- Build/run with
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, use Normal.
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.zip
Description
Reviewing a customer issue, we noticed usage of
RegexOptions.Compiledimpacts 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.Compiledwas 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 androidMainActivity.csand put_ = new Regex(@"([^;=]+)=([^;]+)(?:;\s*)?", RegexOptions.Compiled);in theOnCreate()method.dotnet build -c Release -t:RunExpected behavior
RegexOptions.Compileddoesn't have a significant impact to Android startup. (Or we have a feature flag to turn it off)Actual behavior
RegexOptions.Compiledhas 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 traceoutput: regexoptions.compiled.zip