{"id":18645439,"url":"https://github.com/cscott/babybird","last_synced_at":"2025-10-16T05:17:17.716Z","repository":{"id":57189048,"uuid":"47290377","full_name":"cscott/babybird","owner":"cscott","description":"A slimmed down Promise implementation, built for speed.","archived":false,"fork":false,"pushed_at":"2018-08-02T02:40:41.000Z","size":117,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-26T09:34:33.797Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cscott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-02T21:43:43.000Z","updated_at":"2023-09-08T17:04:16.000Z","dependencies_parsed_at":"2022-09-15T03:53:32.379Z","dependency_job_id":null,"html_url":"https://github.com/cscott/babybird","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cscott/babybird","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cscott%2Fbabybird","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cscott%2Fbabybird/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cscott%2Fbabybird/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cscott%2Fbabybird/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cscott","download_url":"https://codeload.github.com/cscott/babybird/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cscott%2Fbabybird/sbom","scorecard":{"id":310755,"data":{"date":"2025-08-11","repo":{"name":"github.com/cscott/babybird","commit":"a97138a6bf4b6c3228bcb535e1df75d3f66b27af"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.4,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: npmCommand not pinned by hash: bench:13","Warn: npmCommand not pinned by hash: bench:19","Warn: npmCommand not pinned by hash: bench:25","Warn: npmCommand not pinned by hash: bench:31","Info:   0 out of   4 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-17T23:08:39.061Z","repository_id":57189048,"created_at":"2025-08-17T23:08:39.061Z","updated_at":"2025-08-17T23:08:39.061Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279158872,"owners_count":26116349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-16T02:00:06.019Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T06:15:53.505Z","updated_at":"2025-10-16T05:17:17.674Z","avatar_url":"https://github.com/cscott.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babybird\n[![NPM][NPM1]][NPM2] [![Promises/A+ 1.0 compliant][PAP1]][PAP2]\n\n[![Build Status][1]][2] [![dependency status][3]][4] [![dev dependency status][5]][6]\n\nA very fast standards-compliant [ES2015] Promise library for node.\n\nThere are several fast promise implementations out there, like\n[`bluebird`], but they all add a bunch of stuff that's not in the\n[ES2015] Promise spec.  Further, as they've added more and more\nfeatures they've grown so complex that they can't be easily audited\nagainst the ES2015 spec (or the official `test262` test suite).\n\nThe `babybird` library is a stripped-down \"just ES2015\" Promise\nimplementation, which passes the Promises/A+ and `test262` test\nsuites.  It is very competitive with the performance of [`bluebird`],\nwithout having to give up standards compliance.  On the `doxbee`\nbenchmark running under node 5.1.0, `babybird` is 2.4 times faster\nthan native Promises, 4 times faster than the Promise implementation\nin [`core-js`], and almost 9 times faster than the Promise\nimplementation in [`es6-shim`].  The performance improvement is even\ngreater when running under node 0.10.\n\nFurther, `babybird` supports subclassing (as all ES2015 Promise\nimplementations ought).  This means that if you'd like additional\nbells and whistles on your Promises, you can add then via subclassing\nand without stomping on the global Promise.  In fact, the [`prfun`]\nlibrary provides much the same feature set as `bluebird`, but with a\nclean separation of concerns.  Further, `prfun` runs on top of *any*\nES2015-compliant Promise implementation, so if `babybird` is someday\nsupplanted, you can just swap out the core Promise implementation\nunderneath `prfun` without having to update any of your uses of the\ncore ES2015 or extended `prfun` API.\n\n## Usage\n```\nnpm install babybird\n```\n\n```javascript\nvar Promise = require('babybird');\n```\n\nThe `babybird` library plays very nicely with [`prfun`], if you'd like\na few bells and whistles with your library.  I recommend creating a\nnew module, named (say) `promise.js`, with these contents:\n```javascript\nmodule.exports = require('prfun/wrap')(require('babybird'));\n```\nand then using the wrapped promises this way:\n```javascript\nvar Promise = require('./promise.js');\n```\n\n## Benchmarks\nThese benchmarks are derived from the benchmarks included with\n`bluebird`.  A few of the bluebird test cases have been forked to\nadd \"fair\" versions, since bluebird obtained some of its speed by\nusing a faster `promisify` method than that provided to other\npromise implementations, and by using a few `bluebird`-specific\nAPIs which appeared to be tuned for the benchmark.\n\nYou can reproduce these results using `npm run bench`.\n\n### Node 0.10\n```\nresults for 20000 parallel executions, 1 ms per I/O op\n\nfile                                         time(ms)  slowdown  memory(MB)\ncallbacks-baseline.js                             819      0.48  32.99\npromises-bluebird.js                             1383      0.81  50.59\npromises-bluebird-fair.js                        1715      1.00  39.02\npromises-cscott-babybird-noall.js                1870      1.09  41.19\npromises-cscott-babybird.js                      1925      1.12  61.81\npromises-cscott-babybird-prfun.js                1991      1.16  48.60\npromises-then-promise-es6.js                     3084      1.80  64.54\npromises-then-promise.js                         3112      1.81  64.39\npromises-paulmillr-es6shim.js                   12475      7.27  94.20\npromises-zloirock-corejs.js                     18695     10.90  94.11\n\nPlatform info:\nLinux 4.2.0-1-amd64 ia32\nNode.JS 0.10.40\nV8 3.14.5.9\nIntel(R) Core(TM) i7 CPU       L 640  @ 2.13GHz × 4\n```\n\n### Node 5.1.0\n```\nresults for 20000 parallel executions, 1 ms per I/O op\n\nfile                                         time(ms)  slowdown  memory(MB)\ncallbacks-baseline.js                             826      0.53  29.29\npromises-bluebird-generator.js                   1105      0.71  25.49\npromises-bluebird-generator-fair.js              1113      0.72  28.27\npromises-cscott-babybird-prfun-generator.js      1202      0.77  33.68\npromises-bluebird-fair.js                        1553      1.00  51.38\npromises-cscott-babybird-noall.js                1623      1.05  65.25\npromises-bluebird.js                             1643      1.06  43.66\npromises-cscott-babybird-prfun.js                1707      1.10  72.33\npromises-cscott-babybird.js                      1724      1.11  72.82\npromises-then-promise-es6.js                     2985      1.92  106.96\npromises-then-promise.js                         3004      1.93  106.69\npromises-ecmascript6-native.js                   3770      2.43  176.96\npromises-zloirock-corejs.js                      6298      4.06  155.89\npromises-paulmillr-es6shim.js                   13892      8.95  227.61\n\nPlatform info:\nLinux 4.2.0-1-amd64 ia32\nNode.JS 5.1.0\nV8 4.6.85.31\nIntel(R) Core(TM) i7 CPU       L 640  @ 2.13GHz × 4\n```\n\n## Optimization notes\n\nThe `babybird` implementation began with a fairly faithful mechanical\ntranslation of the [ES6 Promise spec] into JavaScript.  In this\nsection I'm going to list the optimizations which were then applied,\nroughly ordered so that those with the largest effect on performance\ncome first.  This is only a very rough ordering, however.\n\n* Use the `asap` package and reuse task objects instead of calling\n  `setImmediate` directly.  This avoids almost all allocation when\n  dispatching asynchronous handlers. (Commit [`eb1f4ea7`] and [`3216461f`])\n* Avoid creating a new `PromiseCapability` in `Promise#then` if the\n  return value will be discarded --- for example, in the\n  `PromiseResolveThenableJob` (when a `Promise` is resolved to another\n  `Promise`) and in the implementation of `Promise.all` and\n  `Promise.race`.  Since creating a `PromiseCapability` calls a\n  user-supplied `Promise` constructor, and this call is\n  user-observable, we can only perform this optimization when we are\n  certain the constructor does not have side effects.  We call\n  this the **\"`then0` optimization\"**.\n  (Commit [`919d7aaf`], [`f717a7b1`], [`3a1bf92a`])\n* Further optimize `Promise#then` by bypassing the standard `Promise`\n  constructor, which requires the creation of three separate closures\n  (the `executor` function and separate `resolve` and `reject` functions).\n  When we know that the constructor is safe, we use an internal-only\n  constructor which uses default `resolve`/`reject` implementations\n  without requiring allocation.  The native `Promise` implementation\n  in v8 contains a\n  [version of this optimization](https://github.com/v8/v8/blob/bc55af3c97d6a7552a409e1b79158c3192908c57/src/js/promise.js#L237).\n  We call this the **\"`PromiseCapability` optimization\"**.\n  (Commit [`b6eea14d`])\n* Use a free list to reuse `PromiseCapability` objects and avoid\n  unnecessary allocation inside `Promise#then`. (Commit [`9f27ecd4`])\n* Inline the reaction array into the Promise object, with special\n  attention to the first element.  Most Promises only get a single\n  handler registered, so we can avoid the array allocations entirely\n  for this common case. We further combined the `state` and `reaction\n  length` fields to reduce memory further. We call this the\n  **\"Promise fields optimization\"**.\n  (Commit [`6cad108a`] and [`dd0c7e4d`])\n* Separate the `createResolvingFunctions` implementation for\n  the `Promise` constructor and `Promise#then`.  For the constructor,\n  reuse the `state` field to track the `alreadyResolved` state, to\n  avoid allocating an extra boolean for this common case. (Commit [`ed96b474`])\n* Specialize `Promise.all` and `Promise.race` if the argument is a\n  true array, avoiding the overhead of using `Iterator` objects.\n* Avoid the use of `try`/`catch`, since their presence deoptimizes\n  the entire function containing them.  Where necessitated by the ES6\n  specification (calling user-provided handlers, for example),\n  encapsulate the `try`/`catch` in separate functions to contain the scope\n  of deoptimization. (Commit [`28a151ae`])\n* Additional micro-optimizations, many informed by [IRHydra2]: avoid\n  the use of `Object#toString` on the fast path, split some functions\n  to better allow call site specialization, avoid some polymorphism,\n  avoid use of `arguments`, and improve the implementation of the\n  `TypeIsObject` check.\n\nIn addition, we made some improvements to [`prfun`]'s `Promise.async`\nimplementation to take advantage of the `then0` optimization (commit\n[`0e7dd8ce`]).  This allows even greater performance when writing\nasync code using generators, as it avoids the necessity of creating\nan extra `Promise` at every `yield`.\n\nThe performance implications of the standard `Promise` constructor\nand field layout were raised by the author of [`bluebird`] on\n[StackExchange](http://programmers.stackexchange.com/a/279003).\nThis explanation is somewhat incomplete: the performance advantage\nof bluebird's `promisify` is somewhat overstated, and the\n\"`then0`\" and \"`PromiseCapability`\" optimizations are not mentioned---but\nthese prove to be very significant.  It appears that the best\nway to optimize a `Promise` is avoid creating it entirely (the\n\"`then0`\" optimization).  If you have to create it, avoid the\ncreation of three closures and a `PromiseCapability` object\nif you can (the \"`PromiseCapability`\" optimization).  And then\nfinally, if you must, at least take care to avoid creating\nunnecessary reaction arrays (the \"Promise fields\" optimization).\n\nIt is also the case that avoiding the naive use of `setImmediate`\nconfers a significant performance advantage, which I don't\nbelieve is widely discussed.\n\n### Subclass support\nThe primary limitation of the `then0` and `PromiseCapability`\noptimizations is that they require the `Promise` subclass'\nconstructor to be side-effect-free, and not to do anything with\nthe provided `executor` function except pass it unmodified to\nits superclass constructor.  If you wish to use a `Promise`\nsubclass constructor which does not adhere to these rules,\nthen you should use `require('babybird/strict-constructors')`\n(or `require('babybird/strict')` if your `Promise` subclass\nis especially badly-behaved).  You can then turn on these\nYou can then turn on these optimizations on a subclass-by-subclass\nbasis by setting `PromiseSubclass.noSideEffects = true` where\nappropriate.  (The [`prfun`] library already sets `noSideEffects`\non the subclass it creates.)\n\n## License\n\nCopyright (c) 2015-2016 C. Scott Ananian\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\nall copies 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\nTHE SOFTWARE.\n\n[ES2015]:     http://www.ecma-international.org/ecma-262/6.0/\n[`bluebird`]: https://github.com/petkaantonov/bluebird\n[`es6-shim`]: https://github.com/paulmillr/es6-shim\n[`core-js`]:  https://github.com/zloirock/core-js\n[`prfun`]:    https://github.com/cscott/prfun\n[ES6 Promise spec]: http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects\n[IRHydra2]:   http://mrale.ph/irhydra/2/\n[`6cad108a`]: https://github.com/cscott/babybird/commit/6cad108aa1cbc90954a40c964804ba8ee3070bd7\n[`eb1f4ea7`]: https://github.com/cscott/babybird/commit/eb1f4ea70cee543198d03fd06f69a73f02702a5d\n[`3216461f`]: https://github.com/cscott/babybird/commit/3216461f3e6583cbee46e93459f560544f45bf47\n[`dd0c7e4d`]: https://github.com/cscott/babybird/commit/dd0c7e4daa39d09e67a65d35bcec563ed2b570bc\n[`28a151ae`]: https://github.com/cscott/babybird/commit/28a151aeabe4cf493b4affa5e433ccc04213cdee\n[`ed96b474`]: https://github.com/cscott/babybird/commit/ed96b47435e0e53b5bdcdbc0b152686e91e78abe\n[`919d7aaf`]: https://github.com/cscott/babybird/commit/919d7aaf3239405e52fa5483ce1a2ffa48e40893\n[`f717a7b1`]: https://github.com/cscott/babybird/commit/f717a7b1b3f517df9cb40cfefd40d929ffe85d86\n[`3a1bf92a`]: https://github.com/cscott/babybird/commit/3a1bf92a4bb61512fa45af25d62dd478e9e2b3ad\n[`b6eea14d`]: https://github.com/cscott/babybird/commit/b6eea14d57852654d8eaf9d62f35b5e52d321479\n[`9f27ecd4`]: https://github.com/cscott/babybird/commit/9f27ecd44c611f90e990e0c78167e1e8cc71fffc\n[`0e7dd8ce`]: https://github.com/cscott/prfun/commit/0e7dd8ceedf0a429ad40fffd3c0e8c1f48a7e87e\n\n\n[NPM1]: https://nodei.co/npm/babybird.png\n[NPM2]: https://nodei.co/npm/babybird/\n\n[1]: https://travis-ci.org/cscott/babybird.png\n[2]: https://travis-ci.org/cscott/babybird\n[3]: https://david-dm.org/cscott/babybird.png\n[4]: https://david-dm.org/cscott/babybird\n[5]: https://david-dm.org/cscott/babybird/dev-status.png\n[6]: https://david-dm.org/cscott/babybird#info=devDependencies\n\n[PAP1]: https://promisesaplus.com/assets/logo-small.png\n[PAP2]: https://promisesaplus.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcscott%2Fbabybird","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcscott%2Fbabybird","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcscott%2Fbabybird/lists"}