Repository navigation
perf: cache parsed req.query per request - #7517
Open
Abdel-Monaam-Aouini wants to merge 2 commits into
Open
Abdel-Monaam-Aouini wants to merge 2 commits into
Abdel-Monaam-Aouini wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
req.queryis a getter that runs the query parser on every access. A handler (or middleware plus handler) that reads it more than once parses the same string each time. For a 5 param query I measured ~1.2us per access with the simple parser and ~3.6us withextended.This keeps the parsed result on the request and reuses it while
req.urland thequery parserfunction are the same. If either changes (url rewrite, setting changed) it parses again, and a parser that throws is not cached.One behavior change: repeated reads of
req.querynow return the same object within a request, so a change likereq.query.x = 1is kept for later reads. Before, each read returned a new object and the change was lost. Happy to drop this if you think that is not acceptable.Added tests for single parse per request, no sharing between requests, url and setting changes, parser errors, disabled parser and mounted sub apps.