-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Do not emit unused code with Request Delegate Generator #48381
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
Comments
It is a complexity trade off but we've definitely got logic already where we omit certain types entirely based on the endpoints they are defined. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
@mitchdenny is this the sort of issue where we'd take a community PR? I'm hoping we can apply the 'help wanted' label whenever we'd take a community PR and believe we would have time to review and accept one (which of course is not always the case, eg., if something would likely need a lot of collaboration) |
I think we would absolutely take a PR on this. |
I'll see if I can come up with a PR to address this that doesn't make things too complicated. |
Proposed fix in #48426. |
Do not emit unused private fields for HTTP verbs that are not used by any of the user-code endpoints. Resolves dotnet#48381.
* Do not emit unused fields in RDG source Do not emit unused private fields for HTTP verbs that are not used by any of the user-code endpoints. Resolves #48381. * Move verbs to incremental pipeline Use another incremental pipeline to produce the HTTP verbs. * Add custom comparer Add custom comparer for endpoints by their HTTP method.
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
While looking at the code for
RequestDelegateGeneratorSources
to see if I could see the source of the bug for #48379 I noticed that private static constants are emitted for all HTTP methods, whether or not they are actually used:aspnetcore/src/Http/Http.Extensions/gen/RequestDelegateGeneratorSources.cs
Lines 648 to 652 in 39564d5
In the following generated code, only
GetVerb
andPostVerb
are used:The memory and IL size would be ever so slightly smaller if the fields weren't emitted (assuming the compiler isn't removing them anyway). This is of course a micro-optimisation, so feel free to close this suggestion if the complexity of the generator code isn't worth changing it to detect which of the arrays are actually needed.
Describe the solution you'd like
The source generator only emits the string arrays that are needed by the endpoints used in the compilation.
Additional context
No response
The text was updated successfully, but these errors were encountered: