mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
Improve Zed's startup time (#65170)
## First commit: Avoid process enumeration during macOS startup Read the real UID with getuid() instead of enumerating processes. Keep the channel offsets, UID wrapping, and handshake unchanged. Measurements (warm macOS launches): - Time to presentation: median 525 ms -> 479 ms over 30 paired launches (release-fast). ## Second commit: Reduce startup work and redraw before window reveal Skip redundant settings recomputation, migration formatting, and colour-scale construction. Request a redraw of hidden macOS windows before revealing them. Measurements (warm macOS launches): - Startup work, time to selected presentation: paired median reductions of 7.5 ms and 10.7 ms in two runs of 30 pairs. - Window reveal, time to first captured text: paired median reduction of 18.4 ms over 30 pairs. Release Notes: - Slightly improved Zed's startup time in general case - [GPUI] N/A
This commit is contained in:
Generated
+1
@@ -22490,6 +22490,7 @@ dependencies = [
|
||||
"migrator",
|
||||
"mimalloc",
|
||||
"miniprofiler_ui",
|
||||
"nix 0.30.1",
|
||||
"node_runtime",
|
||||
"notifications",
|
||||
"onboarding",
|
||||
|
||||
@@ -1436,9 +1436,9 @@ impl ExtensionStore {
|
||||
.chain(languages_to_readd.iter().map(|(name, _)| name))
|
||||
.collect::<Vec<_>>();
|
||||
if !semantic_token_rules_to_remove.is_empty() {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
SettingsStore::update_global(cx, |store, _| {
|
||||
for language in semantic_token_rules_to_remove {
|
||||
store.remove_language_semantic_token_rules(language.as_ref(), cx);
|
||||
store.remove_language_semantic_token_rules(language.as_ref());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1629,13 +1629,9 @@ impl ExtensionStore {
|
||||
// Register semantic token rules for newly loaded extension languages.
|
||||
if !semantic_token_rules_to_add.is_empty() {
|
||||
this.update(cx, |_, cx| {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
SettingsStore::update_global(cx, |store, _| {
|
||||
for (language_name, rules) in semantic_token_rules_to_add {
|
||||
store.set_language_semantic_token_rules(
|
||||
language_name.0.clone(),
|
||||
rules,
|
||||
cx,
|
||||
);
|
||||
store.set_language_semantic_token_rules(language_name.0.clone(), rules);
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1788,14 +1788,18 @@ impl PlatformWindow for MacWindow {
|
||||
fn activate(&self) {
|
||||
let lock = self.0.lock();
|
||||
let window = lock.native_window;
|
||||
let view = lock.native_view.as_ptr();
|
||||
let closed = lock.closed.clone();
|
||||
let executor = lock.foreground_executor.clone();
|
||||
executor
|
||||
.spawn(async move {
|
||||
if !closed.load(Ordering::Acquire) {
|
||||
unsafe {
|
||||
let _: () = msg_send![window, makeKeyAndOrderFront: nil];
|
||||
let window = unsafe { &*window.cast::<Objc2NSWindow>() };
|
||||
if !window.isVisible() {
|
||||
let view = unsafe { &*view.cast::<Objc2NSView>() };
|
||||
view.setNeedsDisplay(true);
|
||||
}
|
||||
window.makeKeyAndOrderFront(None);
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
@@ -355,8 +355,8 @@ fn register_language(
|
||||
) {
|
||||
let config = load_config(name);
|
||||
if let Some(rules) = &semantic_token_rules {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
store.set_language_semantic_token_rules(config.name.0.clone(), rules.clone(), cx);
|
||||
SettingsStore::update_global(cx, |store, _| {
|
||||
store.set_language_semantic_token_rules(config.name.0.clone(), rules.clone());
|
||||
});
|
||||
}
|
||||
for adapter in adapters {
|
||||
|
||||
@@ -1032,27 +1032,17 @@ impl SettingsStore {
|
||||
/// or by third-party extensions (via `semantic_token_rules.json` in their language
|
||||
/// directories). They are stored separately from the global rules and are only
|
||||
/// applied to buffers of the matching language by the `SemanticTokenStylizer`.
|
||||
///
|
||||
/// This triggers a settings recomputation so that observers (e.g. `LspStore`)
|
||||
/// are notified and can invalidate cached stylizers.
|
||||
pub fn set_language_semantic_token_rules(
|
||||
&mut self,
|
||||
language: SharedString,
|
||||
rules: SemanticTokenRules,
|
||||
cx: &mut App,
|
||||
) {
|
||||
self.language_semantic_token_rules.insert(language, rules);
|
||||
self.recompute_values(None, cx);
|
||||
}
|
||||
|
||||
/// Removes language-specific semantic token rules for the given language.
|
||||
///
|
||||
/// This should be called when an extension that registered rules for a language
|
||||
/// is unloaded. Triggers a settings recomputation so that observers (e.g.
|
||||
/// `LspStore`) are notified and can invalidate cached stylizers.
|
||||
pub fn remove_language_semantic_token_rules(&mut self, language: &str, cx: &mut App) {
|
||||
pub fn remove_language_semantic_token_rules(&mut self, language: &str) {
|
||||
self.language_semantic_token_rules.remove(language);
|
||||
self.recompute_values(None, cx);
|
||||
}
|
||||
|
||||
/// Returns the language-specific semantic token rules for the given language,
|
||||
|
||||
@@ -61,6 +61,12 @@ impl Connection {
|
||||
|
||||
let mut did_migrate = false;
|
||||
for (index, migration) in migrations.iter().enumerate() {
|
||||
if completed_migrations
|
||||
.get(index)
|
||||
.is_some_and(|(_, _, completed)| completed.as_str() == *migration)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let migration =
|
||||
sqlformat::format(migration, &sqlformat::QueryParams::None, Default::default());
|
||||
if let Some((_, _, completed_migration)) = completed_migrations.get(index) {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use gpui::{Hsla, Rgba};
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use crate::ColorScale;
|
||||
use crate::scale::{ColorScaleSet, ColorScales};
|
||||
use crate::{SystemColors, ThemeColors};
|
||||
|
||||
pub(crate) fn neutral() -> ColorScaleSet {
|
||||
sand()
|
||||
pub(crate) fn neutral() -> &'static ColorScaleSet {
|
||||
static NEUTRAL: LazyLock<ColorScaleSet> = LazyLock::new(sand);
|
||||
&NEUTRAL
|
||||
}
|
||||
|
||||
const ADDED_COLOR: Hsla = Hsla {
|
||||
|
||||
@@ -236,6 +236,9 @@ zlog.workspace = true
|
||||
zlog_settings.workspace = true
|
||||
ztracing.workspace = true
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
nix = { workspace = true, features = ["user"] }
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
etw_tracing.workspace = true
|
||||
windows = { workspace = true, features = ["Win32_System_Console", "Win32_System_Pipes"] }
|
||||
|
||||
@@ -5,8 +5,7 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use sysinfo::System;
|
||||
|
||||
use nix::unistd::getuid;
|
||||
use release_channel::ReleaseChannel;
|
||||
|
||||
const LOCALHOST: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
|
||||
@@ -34,42 +33,17 @@ fn address() -> SocketAddr {
|
||||
ReleaseChannel::Stable => 43737 + (2 * USER_BLOCK),
|
||||
ReleaseChannel::Nightly => 43737 + (3 * USER_BLOCK),
|
||||
};
|
||||
let mut user_port = port;
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_all();
|
||||
if let Ok(current_pid) = sysinfo::get_current_pid()
|
||||
&& let Some(uid) = sys
|
||||
.process(current_pid)
|
||||
.and_then(|process| process.user_id())
|
||||
{
|
||||
let uid_u32 = get_uid_as_u32(uid);
|
||||
// Ensure that the user ID is not too large to avoid overflow when
|
||||
// calculating the port number. This seems unlikely but it doesn't
|
||||
// hurt to be safe.
|
||||
let max_port = 65535;
|
||||
let max_uid: u32 = max_port - port as u32;
|
||||
let wrapped_uid: u16 = (uid_u32 % max_uid) as u16;
|
||||
user_port += wrapped_uid;
|
||||
}
|
||||
let uid = getuid().as_raw();
|
||||
// Ensure that the user ID is not too large to avoid overflow when
|
||||
// calculating the port number. This seems unlikely but it doesn't
|
||||
// hurt to be safe.
|
||||
let max_uid = u32::from(u16::MAX) - u32::from(port);
|
||||
let wrapped_uid = (uid % max_uid) as u16;
|
||||
let user_port = port + wrapped_uid;
|
||||
|
||||
SocketAddr::V4(SocketAddrV4::new(LOCALHOST, user_port))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn get_uid_as_u32(uid: &sysinfo::Uid) -> u32 {
|
||||
*uid.clone()
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn get_uid_as_u32(uid: &sysinfo::Uid) -> u32 {
|
||||
// Extract the RID which is an integer
|
||||
uid.to_string()
|
||||
.rsplit('-')
|
||||
.next()
|
||||
.and_then(|rid| rid.parse::<u32>().ok())
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
fn instance_handshake() -> &'static str {
|
||||
match *release_channel::RELEASE_CHANNEL {
|
||||
ReleaseChannel::Dev => "Zed Editor Dev Instance Running",
|
||||
|
||||
Reference in New Issue
Block a user