build: Optimize for size and use ThinLTO for release binaries.

After running a variety of Linux release builds of the CLI binary[0]
it seems that this configuration is a good sweet spot when trading
off between runtime performance, binary size, and build times.

From git history it seems that using LTO was originally motivated
by binary size reductions (see linked gist) but we can get much
smaller binaries with much faster links if we switch from the
default release optimization to asking LLVM to optimize aggressively
for size.

If our only priorities were build times and binary size, switching
from opt-level 3 to z without any LTO might be the sweet spot since
it's quite fast to build (again see linked gist). However ThinLTO is
quite fast to build and leaves less performance on the table.

Locally this cuts the time to build a release binary by 2/3 and the
resulting binary is quite usable.

[0] https://gist.github.com/anp/71820f253d4528f313171a57b3b895e7
This commit is contained in:
Adam Perry
2026-05-20 07:44:16 -07:00
parent 05cf2fc4ce
commit 6af5c859fb

View File

@@ -490,7 +490,8 @@ debug = "none"
strip = "symbols"
[profile.release]
lto = "fat"
opt-level = "z"
lto = "thin"
split-debuginfo = "off"
# Because we bundle some of these executables with the TypeScript CLI, we
# remove everything to make the binary as small as possible.