From 6af5c859fb68a26632a78310175f2d6142cea8d8 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Wed, 20 May 2026 07:44:16 -0700 Subject: [PATCH] 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 --- codex-rs/Cargo.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codex-rs/Cargo.toml b/codex-rs/Cargo.toml index ec38a87cff..ce2652924d 100644 --- a/codex-rs/Cargo.toml +++ b/codex-rs/Cargo.toml @@ -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.