-
-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build: use a single top-level tsc -b
for all packages
#3090
Conversation
tsc -b
for all commandstsc -b
for all packages
@@ -4,7 +4,7 @@ | |||
"target": "es2019", | |||
"outDir": "dist", | |||
"lib": ["dom", "es2019"], | |||
"sourceMap": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matches the behaviour from the .swcrc
that we used in production.
name: pkg.name, | ||
manifest: pkg, | ||
}); | ||
const subDirPath = path.resolve(PACKAGES_DIR, subDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used to assume that anything in the packages/
folder was a folder as well. Here, I add a little isDirectory()
check to make sure that we don't assume package/foo
is a folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sad to see swc go, but the numbers speak for themselves.
This PR is an attempt to speed up our build process using
tsc
with TypeScript project references.Motivation
In order to build Electron Forge, we currently run two separate build steps:
.d.ts
): we runtsc --emitDeclarationsOnly
on each package in the monorepo withlerna exec
.lerna exec
. This is aliased tobuild:fast
for JS-only compilation.The problem here is that
tsc
is slow despiteswc
being fast, meaning that although it takes about 1-2 seconds to compile our TypeScript to JavaScript, it also takes over 10 seconds to add the associated type declarations.Changes
The good: adding project references
In order to speed up our
tsc
usage, I decided to try adding TypeScript project references to our monorepo setup. I loosely followed the sample project from RyanCavanaugh/learn-a to get set up with Lerna + project references.Ultimately, this means that we can run
tsc -b
once and get incremental builds! From my testing, this drastically speeds up the full build process for warm builds.The bad: removing SWC
Unfortunately, it seems like it's impossible to run
tsc -b
with--emitDeclarationsOnly
as of TypeScript 4.9, which means that we can't actually generate type declarations only with the quicker tsc method, meaning that an extra SWC step becomes redundant.(However, an unreleased PR microsoft/TypeScript#51241 has landed that will enable us to test this out in the future.)
Testing
To give a clearer picture of the perf numbers, I wanted to run some janky benchmarks. YMMV on how useful these numbers are beyond my specific machine, though.
I tested three separate commands:
yarn build
(tsc + SWC)tsc -b
command (tsc only)yarn build:fast
(only tested for the warm builds because it blows tsc -b out the water for cold build)I also tested three different scenarios:
I then ran each combination of command x scenario 10 times:
Conclusion
Some conclusions I can derive from the numbers:
tsc -b
speed lags behind SWC only, but also includes full type declaration generation.I guess whether or not this PR should land or not should depend on how we value usage of
build:fast
vs having way quicker full builds.