-
-
Notifications
You must be signed in to change notification settings - Fork 750
perf: eliminate conditional check in json strict mode hot path #651
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
base: master
Are you sure you want to change the base?
perf: eliminate conditional check in json strict mode hot path #651
Conversation
Refactor JSON parser creation to return specialized parser functions based on strict mode setting, removing the per-request `if (strict)` conditional check in the parsing hot path.
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.
Pull Request Overview
This PR refactors the JSON parser logic by extracting the parse function into a separate helper function createJsonParser. The refactoring improves code organization by separating parser creation from middleware setup, and fixes an incorrect JSDoc return type annotation.
Key Changes
- Extracted inline
parsefunction into a newcreateJsonParserhelper function that returns the appropriate parser based on thestrictoption - Corrected JSDoc return type annotation for
firstcharfunction from{function}to{string | undefined}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Ref: expressjs/perf-wg#77 A (Baseline):
B (This branch):
My local load test results: cc: @wesleytodd |
|
Ah awesome, yeah the perf tests are still a work in progress. So there is inconsistencies between runs and sometimes you may want to change the test requests or server implementation a bit to get real results. I just threw together some low effort requests with bodies in that PR but feel free to write ones that show the perf improvement even more than this did on your machine. And any feedback on running these is welcome! |
This change refactors the JSON parser to eliminate the per-request
if (strict)conditional check from the parsing hot path.Instead of checking strict mode during parsing, we now create specialized parser functions at middleware initialization based on the strict option.
I'm aware that this introduces some code duplication between the strict and non-strict parser implementations, but I think that is a necessary trade-off.