Skip to content

Conversation

@eerhardt
Copy link
Member

Move the lazy Regex creation code to a delegate that is only set with the RegexRouteConstraint constructor that takes a string regexPattern. This allows for the Regex engine to be trimmed when the regexPattern constructor is trimmed.

Fix #46142

Publishing dotnet new api -aot app on win-x64:

main: 12.1 MB (12,725,760 bytes)
PR: 11.3 MB (11,909,120 bytes)

Move the lazy Regex creation code to a delegate that is only set with the RegexRouteConstraint constructor that takes a string regexPattern. This allows for the Regex engine to be trimmed when the regexPattern constructor is trimmed.

Fix dotnet#46142
@eerhardt eerhardt enabled auto-merge (squash) February 22, 2023 22:44
@davidfowl
Copy link
Member

I do not understand.

@eerhardt eerhardt merged commit ce8e0ce into dotnet:main Feb 23, 2023
@ghost ghost added this to the 8.0-preview2 milestone Feb 23, 2023
@JamesNK
Copy link
Member

JamesNK commented Feb 23, 2023

I do not understand.

We want to trim away new Regex(string, ...). We can't have it lazily called in the regex property because the property is always used by Match. Moving lazily creating the regex to the new RegexRouteConstraint(string) constructor means it's trimmed away along with the constructor.

FYI the alpha constraint still inherits from RegexRouteConstraint, but it doesn't use the base string ctor:

public partial class AlphaRouteConstraint : RegexRouteConstraint, ICachableParameterPolicy
{
/// <summary>
/// Initializes a new instance of the <see cref="AlphaRouteConstraint" /> class.
/// </summary>
public AlphaRouteConstraint() : base(GetAlphaRouteRegex())
{
}
[GeneratedRegex(@"^[A-Za-z]*$")]
private static partial Regex GetAlphaRouteRegex();
}

@eerhardt eerhardt deleted the TrimRegex branch February 23, 2023 14:13
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
@eerhardt eerhardt added the Perf label Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions Perf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve routing RegEx constraint dependency size issue

5 participants