Skip to main content

性能

官方基准

¥Official benchmarks

以下两个图表显示了过去一周每天在所有主要包管理器上运行 GitHub Action 运行器的完整安装所需的时间,这些时间是当天执行的多次运行的平均值,每次运行本身都是多次安装的平均值。

¥The two following graphs show the time it took to run a full install on the GitHub Action runners, every day of the past week, on all major package managers, averaged over multiple runs performed during the day, with each run being itself averaged over multiple installs.

第一张图显示了 Next.js 项目的安装时间,第二张图显示了 Gatsby 项目的安装时间。两条实线都代表 Yarn 的主分支,浅蓝色表示 Yarn PnP 安装,深蓝色表示在 nodeLinker: node-modules 下运行的 Yarn。蓝色虚线代表 Yarn Classic。

¥The first graph shows the install time of a Next.js project, and the second one of a Gatsby project. The two solid lines both represent the master branch of Yarn, with the light blue one being Yarn PnP installs, and the dark blue one being Yarn operating under nodeLinker: node-modules. The dotted blue line represents Yarn Classic.

提示

这只是我们每三个小时在每个工具的最新版本上运行一次的基准测试的一小部分。要查看这些测试的所有变体,请查阅我们专用的 Datadog 仪表板

¥This is only a small subset of the benchmarks we run every three hours on the latest version of each tool. To see all variants of those tests, consult our dedicated Datadog dashboard.

不要从拉取请求中进行基准测试

¥Don't benchmark from pull requests

或者至少在执行此操作时使用私有存储库。

¥Or at least use a private repository when doing that.

当 Yarn 检测到正在运行的环境是公共存储库上的拉取请求时,它会启用各种安全设置。除其他事项外(参见 强化模式),它将默认从远程注册表中提取所有元数据,以确认它们与锁定文件中的内容匹配。这会使安装速度慢得多,但对于保护我们的用户免受 锁文件中毒 的侵害很重要。

¥Yarn enables various security settings when it detects that the running environment is a pull request on a public repository. Amongst others (see Hardened mode), it will by default pull all metadata from the remote registry to confirm they match what's inside the lockfile. This makes installs much slower, but is important to protect our users against lockfile poisoning.

关于收益递减

¥About diminishing returns

在讨论包管理器性能时请记住,这些数字是非常相对的。虽然主要版本和次要版本通常会在安装速度方面有所改进,但缩短几秒钟不会产生重大影响 - 尤其是当这些时间严重依赖于你的确切环境(CI 平台、CPU 数量、网络速度等)和配置(缓存设置)时。

¥Keep in mind when discussing package manager performances that those numbers are very relative. While major and minor releases often come with improvements in terms of install speed, shaving a couple of seconds doesn't have a significant impact - especially when those timings heavily depend on your exact environment (CI platform, cpu count, network speed, ...) and configuration (cache settings).

无论你计划使用 Yarn 还是其他包管理器,请确保不仅根据原始速度做出决定,还要根据更多结构性原因做出决定:它们各自实现的功能、它们各自提供的设置、它们各自设置的优先级。

¥Whether you plan to use Yarn or another package manager, make sure to not only base your decision on raw speed, but also on more structural reasons: features they each implement, settings they each offer, priorities they each set.