Skip to content
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

Use loop for acceptParams #6066

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Conversation

blakeembrey
Copy link
Member

@blakeembrey blakeembrey commented Oct 17, 2024

Using a loop here would improve performance for parsing over splitting into an array and iterating over it, then splitting some more. If we prefer the overall split on ; for readability though, we can still avoid the second split by using indexOf instead. There's also some slices and trim that could be avoided for extra performance but it seemed a little overkill for this function.

Finally, given the code is only used here:

express/lib/response.js

Lines 575 to 584 in a46cfdc

if (key) {
this.set('Content-Type', normalizeType(key).value);
obj[key](req, this, next);
} else if (obj.default) {
obj.default(req, this, next)
} else {
next(createError(406, {
types: normalizeTypes(keys).map(function (o) { return o.value })
}))
}
. If we avoid exporting these utils to users we can just return value only and avoid the rest of the processing entirely.

closes https://github.com/expressjs/security-triage/issues/24

Copy link
Member

@UlisesGascon UlisesGascon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far seems much faster!

basic-example (2)

Report from https://jsbm.dev/ZbkL2XxwbkIOI

@UlisesGascon
Copy link
Member

Should we also backport it to v4?

@jonchurch jonchurch merged commit 805ef52 into expressjs:master Nov 14, 2024
19 checks passed
jonchurch pushed a commit to jonchurch/express that referenced this pull request Nov 14, 2024
jonchurch pushed a commit to jonchurch/express that referenced this pull request Nov 14, 2024
nigrosimone added a commit to nigrosimone/ultimate-express that referenced this pull request Nov 16, 2024
@blakeembrey blakeembrey deleted the be/simplify-params branch November 21, 2024 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants