-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Make HTTP request methods as const strings #12439
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
Make HTTP request methods as const strings #12439
Conversation
Thanks for looking at this, but this behavior was intentional. Using statics allows us to use ReferenceEquals for quick equality checks. Consts get embedded in the calling code and no longer ref-equal. |
To help prevent well-meaning (but not actually desirable) changes like #12439
Since there's nothing in the code to make it clear that this was intentional, I filed #12441 to add a comment describing this. |
Thanks, @anurse. |
No problem! Without that additional context, your proposal to switch to |
I thought the runtime did ensure that string literals and constants were interned and |
That does appear to be the case, I did some rough testing. There may be more complicated stuff at play though. I know @benaadams did some comparison of JIT-generated ASM when he made the change in HeaderNames (#9341) and saw a noticeable performance improvement from switching In general, I think we prefer to be specific here rather than rely on runtime behavior that we can't clearly assert. |
Definitely agree here. |
In the same assembly. Public consts are compiled directly into the il of the referencing assembly if used in default parameters or attributes, so don't share the reference across assemblies. The runtime can intern and dedupe across assembly but it doesn't do it aggressively (would cause start-up/jit perf impact) and a cross-assembly string const in a method body also prevents inlining https://github.com/dotnet/coreclr/issues/23969 Behind a |
Ah, now I remember the issue. Thanks @benaadams! Glad we have a comment there now so people understand why the change was made. |
To help prevent well-meaning (but not actually desirable) changes like #12439
Make HTTP request methods as const strings as it should never be changed.