Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Deserialize `Theme` directly into the heap to avoid stack overflow
Antonio Scandurra1af8f4be19e4
diff --git a/Cargo.lock b/Cargo.lockindex a9c572ba6c7..ca99be02181 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -518,6 +518,7 @@ dependencies = ["menu","project","serde",+ "serde_derive","serde_json","settings","smol",@@ -1097,6 +1098,7 @@ dependencies = ["ipc-channel","plist","serde",+ "serde_derive",][[package]]@@ -1119,6 +1121,7 @@ dependencies = ["rand 0.8.5","rpc","serde",+ "serde_derive","settings","smol","sum_tree",@@ -1228,6 +1231,7 @@ dependencies = ["sea-orm","sea-query","serde",+ "serde_derive","serde_json","settings","sha-1 0.9.8",@@ -1269,6 +1273,7 @@ dependencies = ["postage","project","serde",+ "serde_derive","settings","theme","util",@@ -1739,6 +1744,7 @@ dependencies = ["log","parking_lot 0.11.2","serde",+ "serde_derive","smol","sqlez","sqlez_macros",@@ -1947,6 +1953,7 @@ dependencies = ["rand 0.8.5","rpc","serde",+ "serde_derive","settings","smallvec","smol",@@ -2100,6 +2107,7 @@ dependencies = ["project","search","serde",+ "serde_derive","settings","sysinfo","theme",@@ -2296,6 +2304,7 @@ dependencies = ["regex","rope","serde",+ "serde_derive","serde_json","smol","tempfile",@@ -2667,6 +2676,7 @@ dependencies = ["schemars","seahash","serde",+ "serde_derive","serde_json","simplelog","smallvec",@@ -3276,6 +3286,7 @@ dependencies = ["regex","rpc","serde",+ "serde_derive","serde_json","settings","similar",@@ -3471,6 +3482,7 @@ dependencies = ["parking_lot 0.11.2","postage","serde",+ "serde_derive","serde_json","sha2 0.10.6","simplelog",@@ -3491,6 +3503,7 @@ dependencies = ["prost-types 0.8.0","reqwest","serde",+ "serde_derive","sha2 0.10.6",]@@ -3531,6 +3544,7 @@ dependencies = ["parking_lot 0.11.2","postage","serde",+ "serde_derive","serde_json","smol","unindent",@@ -4450,6 +4464,7 @@ dependencies = ["bincode","plugin_macros","serde",+ "serde_derive",][[package]]@@ -4460,6 +4475,7 @@ dependencies = ["proc-macro2","quote","serde",+ "serde_derive","syn",]@@ -4471,6 +4487,7 @@ dependencies = ["bincode","pollster","serde",+ "serde_derive","serde_json","smol","wasi-common",@@ -4628,6 +4645,7 @@ dependencies = ["regex","rpc","serde",+ "serde_derive","serde_json","settings","sha2 0.10.6",@@ -5250,6 +5268,7 @@ dependencies = ["rand 0.8.5","rsa","serde",+ "serde_derive","smol","smol-timeout","tempdir",@@ -5673,6 +5692,7 @@ dependencies = ["postage","project","serde",+ "serde_derive","serde_json","settings","smallvec",@@ -5861,6 +5881,7 @@ dependencies = ["postage","schemars","serde",+ "serde_derive","serde_json","serde_path_to_error","sqlez",@@ -6481,6 +6502,7 @@ dependencies = ["procinfo","rand 0.8.5","serde",+ "serde_derive","settings","shellexpand","smallvec",@@ -6512,6 +6534,7 @@ dependencies = ["project","rand 0.8.5","serde",+ "serde_derive","settings","shellexpand","smallvec",@@ -6571,6 +6594,7 @@ dependencies = ["indexmap","parking_lot 0.11.2","serde",+ "serde_derive","serde_json","serde_path_to_error","toml",@@ -7564,6 +7588,7 @@ dependencies = ["project","search","serde",+ "serde_derive","serde_json","settings","tokio",@@ -8347,6 +8372,7 @@ dependencies = ["postage","project","serde",+ "serde_derive","serde_json","settings","smallvec",@@ -8473,6 +8499,7 @@ dependencies = ["rust-embed","search","serde",+ "serde_derive","serde_json","serde_path_to_error","settings",diff --git a/Cargo.toml b/Cargo.tomlindex ab8bcd6de83..fd713d42421 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -68,6 +68,7 @@ resolver = "2"[workspace.dependencies]serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1.0", features = ["preserve_order", "raw_value"] }rand = { version = "0.8" }diff --git a/crates/auto_update/Cargo.toml b/crates/auto_update/Cargo.tomlindex 5f672e759f6..8edb1957afc 100644--- a/crates/auto_update/Cargo.toml+++ b/crates/auto_update/Cargo.toml@@ -23,6 +23,7 @@ isahc = "1.7"lazy_static = "1.4"log = "0.4"serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1.0", features = ["preserve_order"] }smol = "1.2.5"tempdir = "0.3.7"diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.tomlindex f2bab22ea71..bf2e583d2cd 100644--- a/crates/cli/Cargo.toml+++ b/crates/cli/Cargo.toml@@ -18,6 +18,7 @@ clap = { version = "3.1", features = ["derive"] }dirs = "3.0"ipc-channel = "0.16"serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }[target.'cfg(target_os = "macos")'.dependencies]core-foundation = "0.9"diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.tomlindex 347424d34e4..6ff66b8ecc4 100644--- a/crates/client/Cargo.toml+++ b/crates/client/Cargo.toml@@ -35,7 +35,8 @@ time = { version = "0.3", features = ["serde", "serde-well-known"] }tiny_http = "0.8"uuid = { version = "1.1.2", features = ["v4"] }url = "2.2"-serde = { version = "*", features = ["derive"] }+serde = { version = "*", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }settings = { path = "../settings" }tempfile = "3"diff --git a/crates/collab/Cargo.toml b/crates/collab/Cargo.tomlindex 873ff8aa448..c25fc287695 100644--- a/crates/collab/Cargo.toml+++ b/crates/collab/Cargo.toml@@ -42,6 +42,7 @@ scrypt = "0.7"sea-orm = { git = "https://github.com/zed-industries/sea-orm", rev = "18f4c691085712ad014a51792af75a9044bacee6", features = ["sqlx-postgres", "postgres-array", "runtime-tokio-rustls"] }sea-query = "0.27"serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = "1.0"sha-1 = "0.9"sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "postgres", "json", "time", "uuid", "any"] }diff --git a/crates/collab_ui/Cargo.toml b/crates/collab_ui/Cargo.tomlindex 2afeb8ad8ae..9b5ca9c1ea9 100644--- a/crates/collab_ui/Cargo.toml+++ b/crates/collab_ui/Cargo.toml@@ -44,6 +44,7 @@ futures = "0.3"log = "0.4"postage = { version = "0.4.1", features = ["futures-traits"] }serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }[dev-dependencies]call = { path = "../call", features = ["test-support"] }diff --git a/crates/db/Cargo.toml b/crates/db/Cargo.tomlindex 496e61b8114..16ec37019a7 100644--- a/crates/db/Cargo.toml+++ b/crates/db/Cargo.toml@@ -24,6 +24,7 @@ lazy_static = "1.4.0"log = { version = "0.4.16", features = ["kv_unstable_serde"] }parking_lot = "0.11.1"serde = { version = "1.0", features = ["derive"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }smol = "1.2"[dev-dependencies]diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.tomlindex 6cb7ef32ec4..6c52ec70e93 100644--- a/crates/editor/Cargo.toml+++ b/crates/editor/Cargo.toml@@ -54,6 +54,7 @@ parking_lot = "0.11"postage = { version = "0.4", features = ["futures-traits"] }rand = { version = "0.8.3", optional = true }serde = { workspace = true }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }smallvec = { version = "1.6", features = ["union"] }smol = "1.2"tree-sitter-rust = { version = "*", optional = true }diff --git a/crates/feedback/Cargo.toml b/crates/feedback/Cargo.tomlindex b224f91a2f2..51f070dd1d3 100644--- a/crates/feedback/Cargo.toml+++ b/crates/feedback/Cargo.toml@@ -25,10 +25,11 @@ postage = { version = "0.4", features = ["futures-traits"] }project = { path = "../project" }search = { path = "../search" }serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }settings = { path = "../settings" }sysinfo = "0.27.1"theme = { path = "../theme" }tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }urlencoding = "2.1.2"util = { path = "../util" }-workspace = { path = "../workspace" }\ No newline at end of file+workspace = { path = "../workspace" }diff --git a/crates/fs/Cargo.toml b/crates/fs/Cargo.tomlindex cd6c8f969c8..66708943f94 100644--- a/crates/fs/Cargo.toml+++ b/crates/fs/Cargo.toml@@ -24,6 +24,7 @@ smol = "1.2.5"regex = "1.5"git2 = { version = "0.15", default-features = false }serde = { workspace = true }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { workspace = true }log = { version = "0.4.16", features = ["kv_unstable_serde"] }libc = "0.2"diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.tomlindex b3e9bda4ec2..65d36753e7b 100644--- a/crates/gpui/Cargo.toml+++ b/crates/gpui/Cargo.toml@@ -42,6 +42,7 @@ resvg = "0.14"schemars = "0.8"seahash = "4.1"serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = "1.0"smallvec = { version = "1.6", features = ["union"] }smol = "1.2"diff --git a/crates/language/Cargo.toml b/crates/language/Cargo.tomlindex 3e6561e4710..26e2d8c53ba 100644--- a/crates/language/Cargo.toml+++ b/crates/language/Cargo.toml@@ -47,6 +47,7 @@ postage = { version = "0.4.1", features = ["futures-traits"] }rand = { version = "0.8.3", optional = true }regex = "1.5"serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1", features = ["preserve_order"] }similar = "1.3"smallvec = { version = "1.6", features = ["union"] }diff --git a/crates/live_kit_client/Cargo.toml b/crates/live_kit_client/Cargo.tomlindex 01457375084..55645732b8f 100644--- a/crates/live_kit_client/Cargo.toml+++ b/crates/live_kit_client/Cargo.toml@@ -14,7 +14,7 @@ name = "test_app"[features]test-support = [- "async-trait",+ "async-trait","collections/test-support","gpui/test-support","lazy_static",@@ -63,9 +63,11 @@ lazy_static = "1.4"objc = "0.2"parking_lot = "0.11.1"serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }sha2 = "0.10"simplelog = "0.9"[build-dependencies]serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1.0", features = ["preserve_order"] }diff --git a/crates/live_kit_server/Cargo.toml b/crates/live_kit_server/Cargo.tomlindex 17ee3cd62e2..319a026456b 100644--- a/crates/live_kit_server/Cargo.toml+++ b/crates/live_kit_server/Cargo.toml@@ -20,6 +20,7 @@ prost = "0.8"prost-types = "0.8"reqwest = "0.11"serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }sha2 = "0.10"[build-dependencies]diff --git a/crates/lsp/Cargo.toml b/crates/lsp/Cargo.tomlindex eb6e02aac91..f37b1c9a453 100644--- a/crates/lsp/Cargo.toml+++ b/crates/lsp/Cargo.toml@@ -23,6 +23,7 @@ lsp-types = "0.91"parking_lot = "0.11"postage = { version = "0.4.1", features = ["futures-traits"] }serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1.0", features = ["raw_value"] }smol = "1.2"diff --git a/crates/plugin/Cargo.toml b/crates/plugin/Cargo.tomlindex 7bf55104659..6b86b19fc85 100644--- a/crates/plugin/Cargo.toml+++ b/crates/plugin/Cargo.toml@@ -6,5 +6,6 @@ publish = false[dependencies]serde = "1.0"+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }bincode = "1.3"plugin_macros = { path = "../plugin_macros" }diff --git a/crates/plugin_macros/Cargo.toml b/crates/plugin_macros/Cargo.tomlindex 32bfc6a01af..e661485373f 100644--- a/crates/plugin_macros/Cargo.toml+++ b/crates/plugin_macros/Cargo.toml@@ -12,4 +12,5 @@ syn = { version = "1.0", features = ["full", "extra-traits"] }quote = "1.0"proc-macro2 = "1.0"serde = "1.0"+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }bincode = "1.3"diff --git a/crates/plugin_runtime/Cargo.toml b/crates/plugin_runtime/Cargo.tomlindex b5cfb9514f3..13efa10dc22 100644--- a/crates/plugin_runtime/Cargo.toml+++ b/crates/plugin_runtime/Cargo.toml@@ -10,6 +10,7 @@ wasmtime-wasi = "0.38"wasi-common = "0.38"anyhow = { version = "1.0", features = ["std"] }serde = "1.0"+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = "1.0"bincode = "1.3"pollster = "0.2.5"diff --git a/crates/project/Cargo.toml b/crates/project/Cargo.tomlindex 68dc57f6145..89ed5563abe 100644--- a/crates/project/Cargo.toml+++ b/crates/project/Cargo.toml@@ -49,6 +49,7 @@ pulldown-cmark = { version = "0.9.1", default-features = false }rand = "0.8.3"regex = "1.5"serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1.0", features = ["preserve_order"] }sha2 = "0.10"similar = "1.3"diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.tomlindex 25c2ce1ca73..ff71a2493e8 100644--- a/crates/rpc/Cargo.toml+++ b/crates/rpc/Cargo.toml@@ -27,6 +27,7 @@ prost = "0.8"rand = "0.8"rsa = "0.4"serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }smol-timeout = "0.6"tracing = { version = "0.1.34", features = ["log"] }zstd = "0.11"diff --git a/crates/search/Cargo.toml b/crates/search/Cargo.tomlindex f36865a89b4..85215c15b26 100644--- a/crates/search/Cargo.toml+++ b/crates/search/Cargo.toml@@ -24,6 +24,7 @@ futures = "0.3"log = { version = "0.4.16", features = ["kv_unstable_serde"] }postage = { version = "0.4.1", features = ["futures-traits"] }serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }smallvec = { version = "1.6", features = ["union"] }smol = "1.2"diff --git a/crates/settings/Cargo.toml b/crates/settings/Cargo.tomlindex c1ec2a6210c..1711bb335bd 100644--- a/crates/settings/Cargo.toml+++ b/crates/settings/Cargo.toml@@ -25,6 +25,7 @@ json_comments = "0.2"postage = { version = "0.4.1", features = ["futures-traits"] }schemars = "0.8"serde = { workspace = true }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { workspace = true }serde_path_to_error = "0.1.4"toml = "0.5"diff --git a/crates/terminal/Cargo.toml b/crates/terminal/Cargo.tomlindex c6f33a0fc76..56a8a3c4522 100644--- a/crates/terminal/Cargo.toml+++ b/crates/terminal/Cargo.toml@@ -30,6 +30,7 @@ anyhow = "1"thiserror = "1.0"lazy_static = "1.4.0"serde = { version = "1.0", features = ["derive"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }[dev-dependencies]rand = "0.8.5"diff --git a/crates/terminal_view/Cargo.toml b/crates/terminal_view/Cargo.tomlindex f12e4be03bd..1e5b9d6070b 100644--- a/crates/terminal_view/Cargo.toml+++ b/crates/terminal_view/Cargo.toml@@ -34,6 +34,7 @@ anyhow = "1"thiserror = "1.0"lazy_static = "1.4.0"serde = { version = "1.0", features = ["derive"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }diff --git a/crates/theme/Cargo.toml b/crates/theme/Cargo.tomlindex 1e9883860fa..a0ef4ad9f8c 100644--- a/crates/theme/Cargo.toml+++ b/crates/theme/Cargo.toml@@ -14,6 +14,7 @@ anyhow = "1.0.38"indexmap = "1.6.2"parking_lot = "0.11.1"serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1.0", features = ["preserve_order"] }serde_path_to_error = "0.1.4"toml = "0.5"diff --git a/crates/theme/src/theme_registry.rs b/crates/theme/src/theme_registry.rsindex d47625289bf..a82ede59f76 100644--- a/crates/theme/src/theme_registry.rs+++ b/crates/theme/src/theme_registry.rs@@ -2,6 +2,7 @@ use crate::{Theme, ThemeMeta};use anyhow::{Context, Result};use gpui::{fonts, AssetSource, FontCache};use parking_lot::Mutex;+use serde::Deserialize;use serde_json::Value;use std::{collections::HashMap, sync::Arc};@@ -56,12 +57,16 @@ impl ThemeRegistry {.with_context(|| format!("failed to load theme file {}", asset_path))?;// Allocate into the heap directly, the Theme struct is too large to fit in the stack.- let mut theme: Arc<Theme> = fonts::with_font_cache(self.font_cache.clone(), || {- serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_slice(&theme_json))+ let mut theme = fonts::with_font_cache(self.font_cache.clone(), || {+ let mut theme = Box::new(Theme::default());+ let mut deserializer = serde_json::Deserializer::from_slice(&theme_json);+ let result = Theme::deserialize_in_place(&mut deserializer, &mut theme);+ result.map(|_| theme)})?;// Reset name to be the file path, so that we can use it to access the stored themes- Arc::get_mut(&mut theme).unwrap().meta.name = name.into();+ theme.meta.name = name.into();+ let theme: Arc<Theme> = theme.into();self.themes.lock().insert(name.to_string(), theme.clone());Ok(theme)}diff --git a/crates/vim/Cargo.toml b/crates/vim/Cargo.tomlindex bd94e48b9e7..dd79d56d8fd 100644--- a/crates/vim/Cargo.toml+++ b/crates/vim/Cargo.toml@@ -13,6 +13,7 @@ neovim = ["nvim-rs", "async-compat", "async-trait", "tokio"][dependencies]serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }itertools = "0.10"log = { version = "0.4.16", features = ["kv_unstable_serde"] }diff --git a/crates/workspace/Cargo.toml b/crates/workspace/Cargo.tomlindex a143e1a2400..06b20684c60 100644--- a/crates/workspace/Cargo.toml+++ b/crates/workspace/Cargo.toml@@ -45,6 +45,7 @@ log = { version = "0.4.16", features = ["kv_unstable_serde"] }parking_lot = "0.11.1"postage = { version = "0.4.1", features = ["futures-traits"] }serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1.0", features = ["preserve_order"] }smallvec = { version = "1.6", features = ["union"] }indoc = "1.0.4"@@ -57,4 +58,4 @@ gpui = { path = "../gpui", features = ["test-support"] }project = { path = "../project", features = ["test-support"] }settings = { path = "../settings", features = ["test-support"] }fs = { path = "../fs", features = ["test-support"] }-db = { path = "../db", features = ["test-support"] }\ No newline at end of file+db = { path = "../db", features = ["test-support"] }diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.tomlindex 6f0227d748f..6a2422f87ca 100644--- a/crates/zed/Cargo.toml+++ b/crates/zed/Cargo.toml@@ -88,6 +88,7 @@ regex = "1.5"rsa = "0.4"rust-embed = { version = "6.3", features = ["include-exclude"] }serde = { version = "1.0", features = ["derive", "rc"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = { version = "1.0", features = ["preserve_order"] }serde_path_to_error = "0.1.4"simplelog = "0.9"diff --git a/plugins/Cargo.lock b/plugins/Cargo.lockindex 3a302d301b0..1e51dd80856 100644--- a/plugins/Cargo.lock+++ b/plugins/Cargo.lock@@ -23,6 +23,7 @@ version = "0.1.0"dependencies = ["plugin","serde",+ "serde_derive","serde_json",]@@ -33,6 +34,7 @@ dependencies = ["bincode","plugin_macros","serde",+ "serde_derive",][[package]]@@ -43,6 +45,7 @@ dependencies = ["proc-macro2","quote","serde",+ "serde_derive","syn",]diff --git a/plugins/json_language/Cargo.toml b/plugins/json_language/Cargo.tomlindex 7e01b9793fd..effbf2ed8ab 100644--- a/plugins/json_language/Cargo.toml+++ b/plugins/json_language/Cargo.toml@@ -6,6 +6,7 @@ edition = "2021"[dependencies]plugin = { path = "../../crates/plugin" }serde = { version = "1.0", features = ["derive"] }+serde_derive = { version = "1.0", features = ["deserialize_in_place"] }serde_json = "1.0"[lib]