{
  "manifest": {
    "name": "reusify",
    "version": "1.0.4",
    "description": "Reuse objects and functions with style",
    "main": "reusify.js",
    "scripts": {
      "lint": "standard",
      "test": "tape test.js | faucet",
      "istanbul": "istanbul cover tape test.js",
      "coverage": "npm run istanbul; cat coverage/lcov.info | coveralls"
    },
    "pre-commit": [
      "lint",
      "test"
    ],
    "repository": {
      "type": "git",
      "url": "git+https://github.com/mcollina/reusify.git"
    },
    "keywords": [
      "reuse",
      "object",
      "performance",
      "function",
      "fast"
    ],
    "author": {
      "name": "Matteo Collina",
      "email": "hello@matteocollina.com"
    },
    "license": "MIT",
    "bugs": {
      "url": "https://github.com/mcollina/reusify/issues"
    },
    "homepage": "https://github.com/mcollina/reusify#readme",
    "engines": {
      "node": ">=0.10.0",
      "iojs": ">=1.0.0"
    },
    "devDependencies": {
      "coveralls": "^2.13.3",
      "faucet": "0.0.1",
      "istanbul": "^0.4.5",
      "pre-commit": "^1.2.2",
      "standard": "^10.0.3",
      "tape": "^4.8.0"
    },
    "_registry": "npm",
    "_loc": "/homez.1033/heliovt/.cache/yarn/v6/npm-reusify-1.0.4-90da382b1e126efc02146e90845a88db12925d76-integrity/node_modules/reusify/package.json",
    "readmeFilename": "README.md",
    "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",
    "licenseText": "The MIT License (MIT)\n\nCopyright (c) 2015 Matteo Collina\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n"
  },
  "artifacts": [],
  "remote": {
    "resolved": "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76",
    "type": "tarball",
    "reference": "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz",
    "hash": "90da382b1e126efc02146e90845a88db12925d76",
    "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==",
    "registry": "npm",
    "packageName": "reusify",
    "cacheIntegrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== sha1-kNo4Kx4SbvwCFG6QhFqI2xKSXXY="
  },
  "registry": "npm",
  "hash": "90da382b1e126efc02146e90845a88db12925d76"
}