From 080e25dd4531f402271c9b3fae9f0314cc19b664 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 19 Mar 2024 01:11:36 +0100 Subject: [PATCH] chore: Merge zed lib with zed binary. TL;DR: - shaves off about 0.5 seconds from most of our debug builds. - It would've slightly regressed release build due to preventing build pipelining, but as a tradeoff I've bumped up codegen-units for zed. \# What did you come up with this time Piotr In our zed repository I've noticed that merely *loading dependencies* in each crate takes non-trivial amount of time (~800ms in case of editor). That is to say, the moment you \`use editor\`, your build time increases by 800ms - this happens just once in crate though, as it looks like compiler has to load .rlibs of all of the referenced dependencies. This is visible under rustc's self-profile. Repro steps on twitter: https://twitter.com/PiotrOsiewicz/status/1762845413072101567 \# How does this commit alleviate this? zed lib + zed bin are on critical path of every build and cumulatively take about 3s to build. This commit bundles all of this up into ~2.2s of bin build time instead. \# Wait, splitting binary targets is good, no? Splitting up a binary target into lib + bin is generally considered to be a good practice, as you can then reuse the lib part elsewhere if needed. It also allows the build to kick off the moment metadata for all of the dependencies is available (thus, you don't need to wait for codegen). However, we do not really use zed as a lib, so the first benefit is not really a thing for us. The latter *is* indeed something we lose out on in release mode (in dev codegen phase of leaf-ish crates is insignificant, as we use shared generics - thus we don't spend much time codegening). That's why I've bumped codegen units for zed crate to 16 in release mode to keep build times in tact. --- Cargo.toml | 3 +++ crates/zed/Cargo.toml | 5 ----- crates/zed/src/main.rs | 2 ++ crates/zed/src/{ => zed}/app_menus.rs | 8 ++++---- crates/zed/src/{ => zed}/only_instance.rs | 0 crates/zed/src/{ => zed}/open_listener.rs | 0 6 files changed, 9 insertions(+), 9 deletions(-) rename crates/zed/src/{ => zed}/app_menus.rs (97%) rename crates/zed/src/{ => zed}/only_instance.rs (100%) rename crates/zed/src/{ => zed}/open_listener.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 421485ee48..1dc3c6cbfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -389,6 +389,9 @@ debug = "limited" lto = "thin" codegen-units = 1 +[profile.release.package] +zed = { codegen-units = 16 } + [workspace.lints.clippy] dbg_macro = "deny" todo = "deny" diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index a70dd0172d..90af8ecda5 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -10,11 +10,6 @@ authors = ["Zed Team "] [lints] workspace = true -[lib] -name = "zed" -path = "src/zed.rs" -doctest = false - [[bin]] name = "Zed" path = "src/main.rs" diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index d1f927dfd0..f222a850b2 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -1,6 +1,8 @@ // Allow binary to be called Zed for a nice application menu when running executable directly #![allow(non_snake_case)] +mod zed; + use anyhow::{anyhow, Context as _, Result}; use backtrace::Backtrace; use chrono::Utc; diff --git a/crates/zed/src/app_menus.rs b/crates/zed/src/zed/app_menus.rs similarity index 97% rename from crates/zed/src/app_menus.rs rename to crates/zed/src/zed/app_menus.rs index e42612c302..fb06f4dcc5 100644 --- a/crates/zed/src/app_menus.rs +++ b/crates/zed/src/zed/app_menus.rs @@ -165,20 +165,20 @@ pub fn app_menus() -> Vec> { Menu { name: "Help", items: vec![ - MenuItem::action("View Telemetry", crate::OpenTelemetryLog), - MenuItem::action("View Dependency Licenses", crate::OpenLicenses), + MenuItem::action("View Telemetry", super::OpenTelemetryLog), + MenuItem::action("View Dependency Licenses", super::OpenLicenses), MenuItem::action("Show Welcome", workspace::Welcome), MenuItem::action("Give Feedback...", feedback::GiveFeedback), MenuItem::separator(), MenuItem::action( "Documentation", - crate::OpenBrowser { + super::OpenBrowser { url: "https://zed.dev/docs".into(), }, ), MenuItem::action( "Zed Twitter", - crate::OpenBrowser { + super::OpenBrowser { url: "https://twitter.com/zeddotdev".into(), }, ), diff --git a/crates/zed/src/only_instance.rs b/crates/zed/src/zed/only_instance.rs similarity index 100% rename from crates/zed/src/only_instance.rs rename to crates/zed/src/zed/only_instance.rs diff --git a/crates/zed/src/open_listener.rs b/crates/zed/src/zed/open_listener.rs similarity index 100% rename from crates/zed/src/open_listener.rs rename to crates/zed/src/zed/open_listener.rs