From 976ab33fb4b262155f518713019e0a8e7b788c9e Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 7 Oct 2026 14:56:09 +0000 Subject: [PATCH] Reduce release binary sizes (#65168) Not sure how worth such optimization is WRT the speed, but for such gains, seems worth opening to discuss? ----------- Optimize selected workspace crates for size and hide Rust exports in macOS bundles. Measurements (release editor executable size): | Platform | Architecture | Before (bytes) | After (bytes) | Reduction (bytes / %) | | --- | --- | ---: | ---: | ---: | | macOS | ARM64 | 258,218,240 | 172,524,896 | 85,693,344 / 33.19% | | Linux | x86_64 | 317,435,136 | 295,344,952 | 22,090,184 / 6.96% | | Windows | x86_64 | 358,987,776 | 256,678,400 | 102,309,376 / 28.50% | Release Notes: - Reduced Zed's binary size --- .cargo/bundle-config.toml | 26 ++++++++++++++++++++++++++ script/bundle-mac | 7 ++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.cargo/bundle-config.toml b/.cargo/bundle-config.toml index 0fc6a68ff96..f00d66614f0 100644 --- a/.cargo/bundle-config.toml +++ b/.cargo/bundle-config.toml @@ -1,3 +1,29 @@ +[profile.release] +opt-level = "z" + +[profile.release.package] +"*" = { opt-level = 3 } +cli = { opt-level = 3 } +editor = { opt-level = 3 } +gpui = { opt-level = 3 } +gpui_apple = { opt-level = 3 } +gpui_linux = { opt-level = 3 } +gpui_macos = { opt-level = 3 } +gpui_platform = { opt-level = 3 } +gpui_shared_string = { opt-level = 3 } +gpui_util = { opt-level = 3 } +gpui_wgpu = { opt-level = 3 } +gpui_windows = { opt-level = 3 } +language = { opt-level = 3 } +multi_buffer = { opt-level = 3 } +project = { opt-level = 3 } +remote_server = { opt-level = 3 } +rope = { opt-level = 3 } +scheduler = { opt-level = 3 } +sum_tree = { opt-level = 3 } +text = { opt-level = 3 } +zed = { codegen-units = 1 } + [target.'cfg(target_os = "linux")'] rustflags = ["-C", "link-args=-Wl,--disable-new-dtags,-rpath,$ORIGIN/../lib"] diff --git a/script/bundle-mac b/script/bundle-mac index 44f36aa1b69..e00632cc50f 100755 --- a/script/bundle-mac +++ b/script/bundle-mac @@ -91,7 +91,12 @@ script/generate-licenses rustup target add $target_triple echo "Compiling zed binaries" -cargo --config .cargo/bundle-config.toml build ${build_flag} ${zed_features} --package zed --package cli --target $target_triple +if [[ "$target_dir" = "release" ]]; then + cargo --config .cargo/bundle-config.toml rustc ${build_flag} ${zed_features} --package zed --bin zed --target $target_triple -- -C 'link-arg=-Wl,-unexported_symbol,__R*' + cargo --config .cargo/bundle-config.toml build ${build_flag} --package cli --target $target_triple +else + cargo --config .cargo/bundle-config.toml build ${build_flag} ${zed_features} --package zed --package cli --target $target_triple +fi # Build remote_server in separate invocation to prevent feature unification from other crates # from influencing dynamic libraries required by it. cargo --config .cargo/bundle-config.toml build ${build_flag} ${remote_server_features} --package remote_server --target $target_triple