-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
perf(fetch): optimize normalizeMethod() #10154
perf(fetch): optimize normalizeMethod() #10154
Conversation
Which was unnecessarily wasteful and taking up 5% of the JS CPU time in the deno_http_native bench
See spec: https://fetch.spec.whatwg.org/#methods
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toUpperCase
is not the same as byte uppercase
in whatwg infra:
"byte uppercase": https://infra.spec.whatwg.org/#byte-uppercase
"toUpperCase": https://tc39.es/ecma262/#sec-string.prototype.touppercase
One is ASCII only, the other uses the "Unicode Default Case Conversion"
I get that, but I don't see how the distinction is meaningful when we only return the upper cased version if it matches a fixed whitelist with strict string equality, I can't see how this could fail or have edge cases. |
It might be the case that some unicode characters "upper case" is an ASCII char. For example that |
The only downside then would be a "false positive" normalization of an ambiguous user-provided method name. It's definitely not best-practice for users to use custom unicode method names ... so I don't think it's a huge issue or spec breaking to normalize in those situations. Even if we want to preserve the previous behaviour, it still makes sense to add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's just move this to rust
Totally. In isolation that change is great, and I think we should land it.
This is a very slippery slope. Having inconsistencies like these are something that some dev somewhere is going to spend hours debugging, because some edge case works (or doesn't work) in Chome, FF, and Safari, but not in Deno. "Correctness is more important than perf" where your words, not mine ;-) https://discord.com/channels/684898665143206084/778060818046386176/830035065669025822 |
I completely agree, it's better to waste machine time than hours of a person's life :) However the tests seem to pass, shouldn't the spec / edge-cases be enforced by the WPT tests ? |
WPT is not yet enabled for |
I'm very much in favor of removing this complexity all together. If someone is using non-upper case methods they deserve the bugs. Please see #10155 |
Pragmatically I wouldn't be opposed to it. The main thing I care about here is that we have a fast path and aren't wasting JS cpu time were we shouldn't be |
This is even more spec incompliant. Someone ran into this a few days ago in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the changes.
Which was unnecessarily wasteful and taking up 5% of the JS CPU time in the
deno_http_native
bench.It's not clear why
byteUpperCase()
was useful, especially since we only return the uppercased method if it matches a whitelist of unambiguous strings.