Main image of article Facebook Yarn Strings JavaScript Packages Faster
[caption id="attachment_137696" align="aligncenter" width="1592"] FacebookYarnDice Facebook Yarn[/caption] If you use JavaScript, chances are good you’re also familiar with the package management client NPM. Facebook used NPM, but wasn’t crazy about its performance. In its stead, the company built Yarn. The reason Facebook built Yarn was scale. While the company likes NPM, it found the larger its own dependency framework, the more its performance slid. There were also issues with consistency and security. In a blog post, Facebook highlighted issues with using NPM on large projects; writing a simple merge to node_modules, for example, would take engineers an entire day. Yarn caches files locally and runs some processes in parallel to help new package loads. It also allows developers to work offline by caching downloaded packages. Screen Shot 2016-10-12 at 11.32.01 AM Though Yarn still allows developers access to NPM, Facebook is positioning it as an alternative package management client. It’s been using Yarn internally for some time, and is quick to point out that, (almost) across the board, Yarn is faster and more reliable at loading dependencies. The lone exception: loading standalone node modules. But its main selling point is package installation. Facebook broke the install process for Yarn into three steps: resolution, fetching and linking. Resolution allows Yarn to resolve dependencies by making requests of the registry (like NPM) and recursively looking up each dependency. Fetching then looks at your global cache directory to see if you’ve already downloaded the package (hey, it happens), and fetches the tarball if it’s not there so you can work offline. Finally, linking simply copies the necessary files from the global cache to your local node_modules directory. 14658612_347000295637068_647258520764284928_n Facebook says Yarn’s three-step process works better because it’s “able to parallelize operations, which maximizes resource utilization and makes the install process faster. On some Facebook projects, Yarn reduced the install process by an order of magnitude, from several minutes to just seconds. Yarn also uses a mutex to ensure that multiple running CLI instances don't collide and pollute each other.” Currently an open source project available on GitHub, Yarn is already used in production situations at Facebook. The company admits that Yarn is probably going to need support, so it's encouraging the Node community to use and iterate on it.