-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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(http): remove allocations checking upgrade and connection header values #17727
Conversation
@@ -471,4 +468,76 @@ function upgradeHttp(req) { | |||
return req[_deferred].promise; | |||
} | |||
|
|||
const spaceCharCode = StringPrototypeCharCodeAt(" ", 0); |
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.
I feel like it's reasonable to only check for plain old spaces instead of all whitespace? I couldn't find anywhere that explained exactly how this is supposed to work though. See past git history when it was checking all kinds of whitespace (and still faster).
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.
https://greenbytes.de/tech/webdav/rfc7230.html#whitespace
At least that particular spec website defines that horizontal tab is also allowed as whitespace.
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.
Should support tab as well for spec compliance.
@@ -14,6 +14,11 @@ import { | |||
} from "./test_util.ts"; | |||
import { join } from "../../../test_util/std/path/mod.ts"; | |||
|
|||
const { | |||
buildCaseInsensitiveCommaValueFinder, | |||
// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol |
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.
I think this could be done via a mapped type:https://discord.com/channels/684898665143206084/688040863313428503/1055570626787672165
Not relevant for this PR though.
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.
It's more complicated, but doesn't require any allocations and seems to be much faster in certain cases
and about the same in others. "match end string" is essentially the equivalent of "no match" and in this case it's about the same except when the string is very long, in which case this is faster.(Edit: it's even better when we only account for spaces and not all whitespace characters. See past edits for past result. I'm not sure if we need to account for other kinds of whitespace though, but it seems reasonable not to)