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

Refactor parameterCount to optimize performance #591

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wojtekmaj
Copy link

Now that body-parser targets Node.js 18, we can finally use String.split to count all the &s in parameterCount body. This makes the function roughly 2x faster in Chrome/Node.js engine (and about 2.5x faster in Safari/Bun engine), according to this jsperf: https://jsperf.app/niqepi/2

Fun fact: if you run this jsperf in Firefox, the old implementation will get speeds unmatched by any other engine, while the new one will be roughly 7x slower. Thankfully, that's only the case in Firefox.

a

Now that body-parser targets Node.js 18, we can finally use String.split to count all the '&'s in parameterCount body. This makes the function roughly 2x faster, according to this jsperf: https://jsperf.app/niqepi/2

Fun fact: if you run this jsperf in Firefox, the old implementation will get record-breaking speeds, while the _new_ one will be roughly 7x slower. Thankfully, both Chrome/Node and Bun/Safari engines show the opposite results.
Copy link
Member

@wesleytodd wesleytodd left a comment

Choose a reason for hiding this comment

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

I didn't quite see the same results in the micro-benchmark, but it was still an improvement. Additionally it is a nice legibility improvement to simplify this method so even if it was relatively equivalent perf I would not mind merging it. Just going to let it sit to see if anyone else had input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants