Merged
Conversation
cf4d18f to
e9e2379
Compare
blakeembrey
commented
Oct 3, 2024
| var obj = {}; | ||
| var len = str.length; | ||
| // RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='. | ||
| var max = len - 2; |
Member
Author
There was a problem hiding this comment.
This was negligible and added complexity, removing.
|
|
||
| // only assign once | ||
| if (undefined === obj[key]) { | ||
| if (!obj.hasOwnProperty(key)) { |
Member
Author
There was a problem hiding this comment.
Before:
> /Users/blakeembrey/.n/bin/node benchmark/parse-top.js
cookie.parse - top sites
15 tests completed.
parse accounts.google.com x 12,372,758 ops/sec ±0.42% (194 runs sampled)
parse apple.com x 12,568,995 ops/sec ±0.72% (188 runs sampled)
parse cloudflare.com x 11,931,561 ops/sec ±0.35% (196 runs sampled)
parse docs.google.com x 11,406,060 ops/sec ±0.30% (195 runs sampled)
parse drive.google.com x 11,407,974 ops/sec ±0.28% (195 runs sampled)
parse en.wikipedia.org x 2,183,413 ops/sec ±0.43% (196 runs sampled)
parse linkedin.com x 2,504,458 ops/sec ±0.56% (195 runs sampled)
parse maps.google.com x 5,811,363 ops/sec ±0.35% (192 runs sampled)
parse microsoft.com x 4,165,492 ops/sec ±0.24% (193 runs sampled)
parse play.google.com x 11,288,231 ops/sec ±0.77% (192 runs sampled)
parse support.google.com x 6,936,106 ops/sec ±0.31% (195 runs sampled)
parse www.google.com x 4,654,382 ops/sec ±0.24% (195 runs sampled)
parse youtu.be x 2,150,212 ops/sec ±0.29% (191 runs sampled)
parse youtube.com x 2,168,764 ops/sec ±0.25% (196 runs sampled)
parse example.com x 1,015,740,156 ops/sec ±0.23% (196 runs sampled)
> /Users/blakeembrey/.n/bin/node benchmark/parse.js
cookie.parse - generic
6 tests completed.
simple x 14,838,760 ops/sec ±1.44% (194 runs sampled)
decode x 5,159,621 ops/sec ±0.37% (196 runs sampled)
unquote x 14,147,216 ops/sec ±0.36% (196 runs sampled)
duplicates x 3,946,673 ops/sec ±0.24% (197 runs sampled)
10 cookies x 1,159,556 ops/sec ±0.27% (196 runs sampled)
100 cookies x 83,567 ops/sec ±0.44% (196 runs sampled)
After:
> /Users/blakeembrey/.n/bin/node benchmark/parse-top.js
cookie.parse - top sites
15 tests completed.
parse accounts.google.com x 9,906,374 ops/sec ±0.40% (192 runs sampled)
parse apple.com x 14,517,233 ops/sec ±0.38% (195 runs sampled)
parse cloudflare.com x 12,549,506 ops/sec ±0.36% (195 runs sampled)
parse docs.google.com x 11,833,067 ops/sec ±0.28% (196 runs sampled)
parse drive.google.com x 11,850,144 ops/sec ±0.28% (196 runs sampled)
parse en.wikipedia.org x 2,243,009 ops/sec ±0.27% (193 runs sampled)
parse linkedin.com x 2,584,784 ops/sec ±0.28% (196 runs sampled)
parse maps.google.com x 6,023,326 ops/sec ±0.29% (196 runs sampled)
parse microsoft.com x 4,113,704 ops/sec ±0.28% (194 runs sampled)
parse play.google.com x 11,830,837 ops/sec ±0.28% (197 runs sampled)
parse support.google.com x 6,963,010 ops/sec ±0.31% (196 runs sampled)
parse www.google.com x 4,606,831 ops/sec ±1.37% (197 runs sampled)
parse youtu.be x 2,167,224 ops/sec ±0.24% (197 runs sampled)
parse youtube.com x 2,172,019 ops/sec ±0.28% (194 runs sampled)
parse example.com x 1,018,534,641 ops/sec ±0.25% (197 runs sampled)
> /Users/blakeembrey/.n/bin/node benchmark/parse.js
cookie.parse - generic
6 tests completed.
simple x 14,448,205 ops/sec ±0.46% (194 runs sampled)
decode x 5,128,678 ops/sec ±0.37% (193 runs sampled)
unquote x 13,934,772 ops/sec ±0.39% (196 runs sampled)
duplicates x 3,914,881 ops/sec ±0.60% (194 runs sampled)
10 cookies x 1,123,799 ops/sec ±0.30% (194 runs sampled)
100 cookies x 86,013 ops/sec ±0.42% (196 runs sampled)
Hard to tell the difference over many runs, seems similar either way but hasOwnProperty would be more technically correct.
4 tasks
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.
Cleaning up and reducing some more code paths.