-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
http: optimize checkIsHttpToken() and checkInvalidHeaderChar() #6570
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
Merged
+217
−50
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
918159e
http: optimize checkIsHttpToken()
mscdex 83432bf
http: optimize checkInvalidHeaderChar()
mscdex 39fdf07
benchmark: increase http token check iterations
mscdex c8fa79f
test: add more http token/value checking tests
mscdex c570182
benchmark: don't convert arguments to numbers
mscdex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
http: optimize checkInvalidHeaderChar()
This commit optimizes checkInvalidHeaderChar() by unrolling the character checking loop a bit. Additionally, some changes to the benchmark runner are needed in order for the included benchmark to be run correctly. Specifically, the regexp used to parse `key=value` parameters contained a greedy quantifier that was causing the `key` to match part of the `value` if `value` contained an equals sign. PR-URL: #6570 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
- Loading branch information
commit 83432bfff1e21797e497aacf4c473db1345f6334
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common.js'); | ||
| const _checkInvalidHeaderChar = require('_http_common')._checkInvalidHeaderChar; | ||
|
|
||
| const bench = common.createBenchmark(main, { | ||
| key: [ | ||
| // Valid | ||
| '', | ||
| '1', | ||
| '\t\t\t\t\t\t\t\t\t\tFoo bar baz', | ||
| 'keep-alive', | ||
| 'close', | ||
| 'gzip', | ||
| '20091', | ||
| 'private', | ||
| 'text/html; charset=utf-8', | ||
| 'text/plain', | ||
| 'Sat, 07 May 2016 16:54:48 GMT', | ||
| 'SAMEORIGIN', | ||
| 'en-US', | ||
|
|
||
| // Invalid | ||
| 'Here is a value that is really a folded header value\r\n this should be \ | ||
| supported, but it is not currently', | ||
| '中文呢', // unicode | ||
| 'foo\nbar', | ||
| '\x7F' | ||
| ], | ||
| n: [5e8], | ||
| }); | ||
|
|
||
| function main(conf) { | ||
| var n = +conf.n; | ||
| var key = conf.key; | ||
|
|
||
| bench.start(); | ||
| for (var i = 0; i < n; i++) { | ||
| _checkInvalidHeaderChar(key); | ||
| } | ||
| bench.end(n); | ||
| } |
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
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.
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.
Either the changes to this file should be a separate commit or the commit log should explain why they are necessary.
Uh oh!
There was an error while loading. Please reload this page.
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.
Initially I had planned it to be in a separate commit but there would then technically be a gap where the new benchmark would be broken (causing the benchmark runner to get in a large loop actually), especially if the benchmark would be cherry picked. I can amend the commit message...
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.
Ok, commit message updated.