-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Remove more code and perf wins #172
Conversation
cf4d18f
to
e9e2379
Compare
if (typeof str !== 'string') { | ||
throw new TypeError('argument str must be a string'); | ||
} | ||
|
||
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; |
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.
This was negligible and added complexity, removing.
@@ -129,7 +124,7 @@ function parse(str, options) { | |||
var key = str.slice(keyStartIdx, keyEndIdx); | |||
|
|||
// only assign once | |||
if (undefined === obj[key]) { | |||
if (!obj.hasOwnProperty(key)) { |
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.
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.
Cleaning up and reducing some more code paths.