| 1 |
{ |
| 2 |
"_id": "reusify", |
| 3 |
"_rev": "9-4d882f20d8910b6d7617cd60cb568749", |
| 4 |
"name": "reusify", |
| 5 |
"description": "Reuse objects and functions with style", |
| 6 |
"dist-tags": { |
| 7 |
"latest": "1.0.4" |
| 8 |
}, |
| 9 |
"versions": { |
| 10 |
"1.0.0": { |
| 11 |
"name": "reusify", |
| 12 |
"version": "1.0.0", |
| 13 |
"description": "Reuse objects and functions with style", |
| 14 |
"main": "reusify.js", |
| 15 |
"scripts": { |
| 16 |
"lint": "standard", |
| 17 |
"test": "tape test.js | faucet " |
| 18 |
}, |
| 19 |
"pre-commit": [ |
| 20 |
"lint", |
| 21 |
"test" |
| 22 |
], |
| 23 |
"repository": { |
| 24 |
"type": "git", |
| 25 |
"url": "git+https://github.com/mcollina/reusify.git" |
| 26 |
}, |
| 27 |
"keywords": [ |
| 28 |
"reuse", |
| 29 |
"object", |
| 30 |
"performance", |
| 31 |
"function", |
| 32 |
"fast" |
| 33 |
], |
| 34 |
"author": { |
| 35 |
"name": "Matteo Collina", |
| 36 |
"email": "[email protected]" |
| 37 |
}, |
| 38 |
"license": "MIT", |
| 39 |
"bugs": { |
| 40 |
"url": "https://github.com/mcollina/reusify/issues" |
| 41 |
}, |
| 42 |
"homepage": "https://github.com/mcollina/reusify#readme", |
| 43 |
"devDependencies": { |
| 44 |
"faucet": "0.0.1", |
| 45 |
"pre-commit": "^1.1.1", |
| 46 |
"standard": "^5.2.1", |
| 47 |
"tape": "^4.2.0" |
| 48 |
}, |
| 49 |
"gitHead": "460929abe2b5a31fc5e6dae6617242b26f9a5364", |
| 50 |
"_id": "[email protected]", |
| 51 |
"_shasum": "6e227aacc80b984c542ebe38e29e4ce82e911170", |
| 52 |
"_from": ".", |
| 53 |
"_npmVersion": "2.14.2", |
| 54 |
"_nodeVersion": "4.0.0", |
| 55 |
"_npmUser": { |
| 56 |
"name": "matteo.collina", |
| 57 |
"email": "[email protected]" |
| 58 |
}, |
| 59 |
"dist": { |
| 60 |
"shasum": "6e227aacc80b984c542ebe38e29e4ce82e911170", |
| 61 |
"tarball": "https://registry.npmjs.org/reusify/-/reusify-1.0.0.tgz" |
| 62 |
}, |
| 63 |
"maintainers": [ |
| 64 |
{ |
| 65 |
"name": "matteo.collina", |
| 66 |
"email": "[email protected]" |
| 67 |
} |
| 68 |
], |
| 69 |
"directories": {} |
| 70 |
}, |
| 71 |
"1.0.1": { |
| 72 |
"name": "reusify", |
| 73 |
"version": "1.0.1", |
| 74 |
"description": "Reuse objects and functions with style", |
| 75 |
"main": "reusify.js", |
| 76 |
"scripts": { |
| 77 |
"lint": "standard", |
| 78 |
"test": "tape test.js | faucet", |
| 79 |
"istanbul": "istanbul cover tape test.js", |
| 80 |
"coverage": "npm run istanbul; cat coverage/lcov.info | coveralls" |
| 81 |
}, |
| 82 |
"pre-commit": [ |
| 83 |
"lint", |
| 84 |
"test" |
| 85 |
], |
| 86 |
"repository": { |
| 87 |
"type": "git", |
| 88 |
"url": "git+https://github.com/mcollina/reusify.git" |
| 89 |
}, |
| 90 |
"keywords": [ |
| 91 |
"reuse", |
| 92 |
"object", |
| 93 |
"performance", |
| 94 |
"function", |
| 95 |
"fast" |
| 96 |
], |
| 97 |
"author": { |
| 98 |
"name": "Matteo Collina", |
| 99 |
"email": "[email protected]" |
| 100 |
}, |
| 101 |
"license": "MIT", |
| 102 |
"bugs": { |
| 103 |
"url": "https://github.com/mcollina/reusify/issues" |
| 104 |
}, |
| 105 |
"homepage": "https://github.com/mcollina/reusify#readme", |
| 106 |
"engines": { |
| 107 |
"node": ">=0.10.0", |
| 108 |
"iojs": ">=1.0.0" |
| 109 |
}, |
| 110 |
"devDependencies": { |
| 111 |
"coveralls": "^2.11.6", |
| 112 |
"faucet": "0.0.1", |
| 113 |
"istanbul": "^0.4.1", |
| 114 |
"pre-commit": "^1.1.1", |
| 115 |
"standard": "^5.2.1", |
| 116 |
"tape": "^4.2.0" |
| 117 |
}, |
| 118 |
"gitHead": "41336018ac1527345d47cb6ec18c5515d0e52b7f", |
| 119 |
"_id": "[email protected]", |
| 120 |
"_shasum": "f53584367adc825c87431917263fc7aa19118693", |
| 121 |
"_from": ".", |
| 122 |
"_npmVersion": "3.4.1", |
| 123 |
"_nodeVersion": "4.2.0", |
| 124 |
"_npmUser": { |
| 125 |
"name": "matteo.collina", |
| 126 |
"email": "[email protected]" |
| 127 |
}, |
| 128 |
"dist": { |
| 129 |
"shasum": "f53584367adc825c87431917263fc7aa19118693", |
| 130 |
"tarball": "https://registry.npmjs.org/reusify/-/reusify-1.0.1.tgz" |
| 131 |
}, |
| 132 |
"maintainers": [ |
| 133 |
{ |
| 134 |
"name": "matteo.collina", |
| 135 |
"email": "[email protected]" |
| 136 |
} |
| 137 |
], |
| 138 |
"directories": {} |
| 139 |
}, |
| 140 |
"1.0.2": { |
| 141 |
"name": "reusify", |
| 142 |
"version": "1.0.2", |
| 143 |
"description": "Reuse objects and functions with style", |
| 144 |
"main": "reusify.js", |
| 145 |
"scripts": { |
| 146 |
"lint": "standard", |
| 147 |
"test": "tape test.js | faucet", |
| 148 |
"istanbul": "istanbul cover tape test.js", |
| 149 |
"coverage": "npm run istanbul; cat coverage/lcov.info | coveralls" |
| 150 |
}, |
| 151 |
"pre-commit": [ |
| 152 |
"lint", |
| 153 |
"test" |
| 154 |
], |
| 155 |
"repository": { |
| 156 |
"type": "git", |
| 157 |
"url": "git+https://github.com/mcollina/reusify.git" |
| 158 |
}, |
| 159 |
"keywords": [ |
| 160 |
"reuse", |
| 161 |
"object", |
| 162 |
"performance", |
| 163 |
"function", |
| 164 |
"fast" |
| 165 |
], |
| 166 |
"author": { |
| 167 |
"name": "Matteo Collina", |
| 168 |
"email": "[email protected]" |
| 169 |
}, |
| 170 |
"license": "MIT", |
| 171 |
"bugs": { |
| 172 |
"url": "https://github.com/mcollina/reusify/issues" |
| 173 |
}, |
| 174 |
"homepage": "https://github.com/mcollina/reusify#readme", |
| 175 |
"engines": { |
| 176 |
"node": ">=0.10.0", |
| 177 |
"iojs": ">=1.0.0" |
| 178 |
}, |
| 179 |
"devDependencies": { |
| 180 |
"coveralls": "^2.13.1", |
| 181 |
"faucet": "0.0.1", |
| 182 |
"istanbul": "^0.4.5", |
| 183 |
"pre-commit": "^1.2.2", |
| 184 |
"standard": "^10.0.0", |
| 185 |
"tape": "^4.7.0" |
| 186 |
}, |
| 187 |
"gitHead": "26c9d4d819562a807c2dacbcd1c79b79d32e18d0", |
| 188 |
"_id": "[email protected]", |
| 189 |
"_npmVersion": "5.3.0", |
| 190 |
"_nodeVersion": "6.11.1", |
| 191 |
"_npmUser": { |
| 192 |
"name": "matteo.collina", |
| 193 |
"email": "[email protected]" |
| 194 |
}, |
| 195 |
"dist": { |
| 196 |
"integrity": "sha512-uvHpBEwqP0XOAlNski7iUcFn0xB75j3FupCnAHVMf1Bosyeo0Jwb/i0QB6PLkMU98NVus1q8NUhpJU1wgWdJCw==", |
| 197 |
"shasum": "e3ca4a613e64daac35d40ff34819e72776bf5d85", |
| 198 |
"tarball": "https://registry.npmjs.org/reusify/-/reusify-1.0.2.tgz" |
| 199 |
}, |
| 200 |
"maintainers": [ |
| 201 |
{ |
| 202 |
"name": "matteo.collina", |
| 203 |
"email": "[email protected]" |
| 204 |
} |
| 205 |
], |
| 206 |
"_npmOperationalInternal": { |
| 207 |
"host": "s3://npm-registry-packages", |
| 208 |
"tmp": "tmp/reusify-1.0.2.tgz_1500537786491_0.876660275971517" |
| 209 |
}, |
| 210 |
"directories": {} |
| 211 |
}, |
| 212 |
"1.0.3": { |
| 213 |
"name": "reusify", |
| 214 |
"version": "1.0.3", |
| 215 |
"description": "Reuse objects and functions with style", |
| 216 |
"main": "reusify.js", |
| 217 |
"scripts": { |
| 218 |
"lint": "standard", |
| 219 |
"test": "tape test.js | faucet", |
| 220 |
"istanbul": "istanbul cover tape test.js", |
| 221 |
"coverage": "npm run istanbul; cat coverage/lcov.info | coveralls" |
| 222 |
}, |
| 223 |
"pre-commit": [ |
| 224 |
"lint", |
| 225 |
"test" |
| 226 |
], |
| 227 |
"repository": { |
| 228 |
"type": "git", |
| 229 |
"url": "git+https://github.com/mcollina/reusify.git" |
| 230 |
}, |
| 231 |
"keywords": [ |
| 232 |
"reuse", |
| 233 |
"object", |
| 234 |
"performance", |
| 235 |
"function", |
| 236 |
"fast" |
| 237 |
], |
| 238 |
"author": { |
| 239 |
"name": "Matteo Collina", |
| 240 |
"email": "[email protected]" |
| 241 |
}, |
| 242 |
"license": "MIT", |
| 243 |
"bugs": { |
| 244 |
"url": "https://github.com/mcollina/reusify/issues" |
| 245 |
}, |
| 246 |
"homepage": "https://github.com/mcollina/reusify#readme", |
| 247 |
"engines": { |
| 248 |
"node": ">=0.10.0", |
| 249 |
"iojs": ">=1.0.0" |
| 250 |
}, |
| 251 |
"devDependencies": { |
| 252 |
"coveralls": "^2.13.1", |
| 253 |
"faucet": "0.0.1", |
| 254 |
"istanbul": "^0.4.5", |
| 255 |
"pre-commit": "^1.2.2", |
| 256 |
"standard": "^10.0.0", |
| 257 |
"tape": "^4.7.0" |
| 258 |
}, |
| 259 |
"gitHead": "1d7ea6292ccf73789503da32caddd920ec8b1ed0", |
| 260 |
"_id": "[email protected]", |
| 261 |
"_npmVersion": "5.4.2", |
| 262 |
"_nodeVersion": "8.6.0", |
| 263 |
"_npmUser": { |
| 264 |
"name": "matteo.collina", |
| 265 |
"email": "[email protected]" |
| 266 |
}, |
| 267 |
"dist": { |
| 268 |
"integrity": "sha512-t8ZQIaf4CHxy8mb4QddDuGOygGiSSiJHMZrtrC+4E7urVtqON4dHVwmV0gfiBOE1tt5p1puae6o8e0b3wkr1Ag==", |
| 269 |
"shasum": "9da7fc786f39400fd6809e3d694b3b28ecd0f38e", |
| 270 |
"tarball": "https://registry.npmjs.org/reusify/-/reusify-1.0.3.tgz" |
| 271 |
}, |
| 272 |
"maintainers": [ |
| 273 |
{ |
| 274 |
"name": "matteo.collina", |
| 275 |
"email": "[email protected]" |
| 276 |
} |
| 277 |
], |
| 278 |
"_npmOperationalInternal": { |
| 279 |
"host": "s3://npm-registry-packages", |
| 280 |
"tmp": "tmp/reusify-1.0.3.tgz_1507322290520_0.9243531748652458" |
| 281 |
}, |
| 282 |
"directories": {} |
| 283 |
}, |
| 284 |
"1.0.4": { |
| 285 |
"name": "reusify", |
| 286 |
"version": "1.0.4", |
| 287 |
"description": "Reuse objects and functions with style", |
| 288 |
"main": "reusify.js", |
| 289 |
"scripts": { |
| 290 |
"lint": "standard", |
| 291 |
"test": "tape test.js | faucet", |
| 292 |
"istanbul": "istanbul cover tape test.js", |
| 293 |
"coverage": "npm run istanbul; cat coverage/lcov.info | coveralls" |
| 294 |
}, |
| 295 |
"pre-commit": [ |
| 296 |
"lint", |
| 297 |
"test" |
| 298 |
], |
| 299 |
"repository": { |
| 300 |
"type": "git", |
| 301 |
"url": "git+https://github.com/mcollina/reusify.git" |
| 302 |
}, |
| 303 |
"keywords": [ |
| 304 |
"reuse", |
| 305 |
"object", |
| 306 |
"performance", |
| 307 |
"function", |
| 308 |
"fast" |
| 309 |
], |
| 310 |
"author": { |
| 311 |
"name": "Matteo Collina", |
| 312 |
"email": "[email protected]" |
| 313 |
}, |
| 314 |
"license": "MIT", |
| 315 |
"bugs": { |
| 316 |
"url": "https://github.com/mcollina/reusify/issues" |
| 317 |
}, |
| 318 |
"homepage": "https://github.com/mcollina/reusify#readme", |
| 319 |
"engines": { |
| 320 |
"node": ">=0.10.0", |
| 321 |
"iojs": ">=1.0.0" |
| 322 |
}, |
| 323 |
"devDependencies": { |
| 324 |
"coveralls": "^2.13.3", |
| 325 |
"faucet": "0.0.1", |
| 326 |
"istanbul": "^0.4.5", |
| 327 |
"pre-commit": "^1.2.2", |
| 328 |
"standard": "^10.0.3", |
| 329 |
"tape": "^4.8.0" |
| 330 |
}, |
| 331 |
"gitHead": "89420d4369258d0b768aaebfb1843951193d315d", |
| 332 |
"_id": "[email protected]", |
| 333 |
"_npmVersion": "5.6.0", |
| 334 |
"_nodeVersion": "8.9.4", |
| 335 |
"_npmUser": { |
| 336 |
"name": "matteo.collina", |
| 337 |
"email": "[email protected]" |
| 338 |
}, |
| 339 |
"dist": { |
| 340 |
"integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", |
| 341 |
"shasum": "90da382b1e126efc02146e90845a88db12925d76", |
| 342 |
"tarball": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz" |
| 343 |
}, |
| 344 |
"maintainers": [ |
| 345 |
{ |
| 346 |
"name": "matteo.collina", |
| 347 |
"email": "[email protected]" |
| 348 |
} |
| 349 |
], |
| 350 |
"_npmOperationalInternal": { |
| 351 |
"host": "s3://npm-registry-packages", |
| 352 |
"tmp": "tmp/reusify-1.0.4.tgz_1516958898700_0.8839292053598911" |
| 353 |
}, |
| 354 |
"directories": {} |
| 355 |
} |
| 356 |
}, |
| 357 |
"readme": "# reusify\n\n[![npm version][npm-badge]][npm-url]\n[![Build Status][travis-badge]][travis-url]\n[![Coverage Status][coveralls-badge]][coveralls-url]\n\nReuse your objects and functions for maximum speed. This technique will\nmake any function run ~10% faster. You call your functions a\nlot, and it adds up quickly in hot code paths.\n\n```\n$ node benchmarks/createNoCodeFunction.js\nTotal time 53133\nTotal iterations 100000000\nIteration/s 1882069.5236482036\n\n$ node benchmarks/reuseNoCodeFunction.js\nTotal time 50617\nTotal iterations 100000000\nIteration/s 1975620.838848608\n```\n\nThe above benchmark uses fibonacci to simulate a real high-cpu load.\nThe actual numbers might differ for your use case, but the difference\nshould not.\n\nThe benchmark was taken using Node v6.10.0.\n\nThis library was extracted from\n[fastparallel](http://npm.im/fastparallel).\n\n## Example\n\n```js\nvar reusify = require('reusify')\nvar fib = require('reusify/benchmarks/fib')\nvar instance = reusify(MyObject)\n\n// get an object from the cache,\n// or creates a new one when cache is empty\nvar obj = instance.get()\n\n// set the state\nobj.num = 100\nobj.func()\n\n// reset the state.\n// if the state contains any external object\n// do not use delete operator (it is slow)\n// prefer set them to null\nobj.num = 0\n\n// store an object in the cache\ninstance.release(obj)\n\nfunction MyObject () {\n // you need to define this property\n // so V8 can compile MyObject into an\n // hidden class\n this.next = null\n this.num = 0\n\n var that = this\n\n // this function is never reallocated,\n // so it can be optimized by V8\n this.func = function () {\n if (null) {\n // do nothing\n } else {\n // calculates fibonacci\n fib(that.num)\n }\n }\n}\n```\n\nThe above example was intended for synchronous code, let's see async:\n```js\nvar reusify = require('reusify')\nvar instance = reusify(MyObject)\n\nfor (var i = 0; i < 100; i++) {\n getData(i, console.log)\n}\n\nfunction getData (value, cb) {\n var obj = instance.get()\n\n obj.value = value\n obj.cb = cb\n obj.run()\n}\n\nfunction MyObject () {\n this.next = null\n this.value = null\n\n var that = this\n\n this.run = function () {\n asyncOperation(that.value, that.handle)\n }\n\n this.handle = function (err, result) {\n that.cb(err, result)\n that.value = null\n that.cb = null\n instance.release(that)\n }\n}\n```\n\nAlso note how in the above examples, the code, that consumes an istance of `MyObject`,\nreset the state to initial condition, just before storing it in the cache.\nThat's needed so that every subsequent request for an instance from the cache,\ncould get a clean instance.\n\n## Why\n\nIt is faster because V8 doesn't have to collect all the functions you\ncreate. On a short-lived benchmark, it is as fast as creating the\nnested function, but on a longer time frame it creates less\npressure on the garbage collector.\n\n## Other examples\nIf you want to see some complex example, checkout [middie](https://github.com/fastify/middie) and [steed](https://github.com/mcollina/steed).\n\n## Acknowledgements\n\nThanks to [Trevor Norris](https://github.com/trevnorris) for\ngetting me down the rabbit hole of performance, and thanks to [Mathias\nBuss](http://github.com/mafintosh) for suggesting me to share this\ntrick.\n\n## License\n\nMIT\n\n[npm-badge]: https://badge.fury.io/js/reusify.svg\n[npm-url]: https://badge.fury.io/js/reusify\n[travis-badge]: https://api.travis-ci.org/mcollina/reusify.svg\n[travis-url]: https://travis-ci.org/mcollina/reusify\n[coveralls-badge]: https://coveralls.io/repos/mcollina/reusify/badge.svg?branch=master&service=github\n[coveralls-url]: https://coveralls.io/github/mcollina/reusify?branch=master\n", |
| 358 |
"maintainers": [ |
| 359 |
{ |
| 360 |
"name": "matteo.collina", |
| 361 |
"email": "[email protected]" |
| 362 |
} |
| 363 |
], |
| 364 |
"time": { |
| 365 |
"modified": "2018-01-26T09:28:18.775Z", |
| 366 |
"created": "2015-09-11T22:13:22.776Z", |
| 367 |
"1.0.0": "2015-09-11T22:13:22.776Z", |
| 368 |
"1.0.1": "2015-12-16T15:33:41.090Z", |
| 369 |
"1.0.2": "2017-07-20T08:03:07.428Z", |
| 370 |
"1.0.3": "2017-10-06T20:38:10.606Z", |
| 371 |
"1.0.4": "2018-01-26T09:28:18.775Z" |
| 372 |
}, |
| 373 |
"homepage": "https://github.com/mcollina/reusify#readme", |
| 374 |
"keywords": [ |
| 375 |
"reuse", |
| 376 |
"object", |
| 377 |
"performance", |
| 378 |
"function", |
| 379 |
"fast" |
| 380 |
], |
| 381 |
"repository": { |
| 382 |
"type": "git", |
| 383 |
"url": "git+https://github.com/mcollina/reusify.git" |
| 384 |
}, |
| 385 |
"author": { |
| 386 |
"name": "Matteo Collina", |
| 387 |
"email": "[email protected]" |
| 388 |
}, |
| 389 |
"bugs": { |
| 390 |
"url": "https://github.com/mcollina/reusify/issues" |
| 391 |
}, |
| 392 |
"license": "MIT", |
| 393 |
"readmeFilename": "README.md", |
| 394 |
"users": { |
| 395 |
"blitzprog": true, |
| 396 |
"majgis": true, |
| 397 |
"hengkiardo": true, |
| 398 |
"bajtos": true |
| 399 |
}, |
| 400 |
"_attachments": {} |
| 401 |
} |