From 6589c0bca337123970a61c11412c04c7b314cc56 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sat, 19 Dec 2020 22:52:22 -0800 Subject: [PATCH] fix yarn-specific perf regression (#590) --- CHANGELOG.md | 6 ++++++ lib/node.ts | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb40113e7b6..4a951bf8cc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +* Fix a performance regression from version 0.8.4 specific to Yarn 2 + + Code using esbuild's `transformSync` function via Yarn 2 experienced a dramatic slowdown in esbuild version 0.8.4 and above. This version added a wrapper script to fix Yarn 2's incompatibility with binary packages. Some code that tries to avoid unnecessarily calling into the wrapper script contained a bug that caused it to fail, which meant that using `transformSync` with Yarn 2 called into the wrapper script unnecessarily. This launched an extra node process every time the esbuild executable was invoked which can be over 6x slower than just invoking the esbuild executable directly. This release should now invoke the esbuild executable directly without going through the wrapper script, which fixes the performance regression. + ## 0.8.24 * Share reference-counted service instances internally ([#600](https://github.com/evanw/esbuild/issues/600)) diff --git a/lib/node.ts b/lib/node.ts index 5f8eaa66476..518f41ec032 100644 --- a/lib/node.ts +++ b/lib/node.ts @@ -45,9 +45,9 @@ let esbuildCommandAndArgs = (): [string, string[]] => { // to if the original location is replaced by our Yarn 2 compatibility hack. // If it exists, we can infer that we are running within Yarn 2 and the // JavaScript API should invoke the binary here instead to avoid a slowdown. - // This is a performance improvement of about 0.1 seconds for Yarn 2 on my - // machine. - let pathForYarn2 = path.join(__dirname, 'esbuild'); + // Calling the binary directly can be over 6x faster than calling the wrapper + // script instead. + let pathForYarn2 = path.join(__dirname, '..', 'esbuild'); if (fs.existsSync(pathForYarn2)) { return [pathForYarn2, []]; }