Improve loading times for extension themes (#40015)
This PR primarily does two things: - replace `serde_json::from_reader` with `serde_json::from_slice`, as the latter is much much faster, even with loading the file into memory first. - runs the initial loading of themes and icon themes coming from extensions in parallel instead of sequential. Measuring the `eager_load_active_theme_and_icon_theme` method, this drastically improves the speed at which this happens (tested this method primarily with debug builds on my MacBook Pro, but the `Before` measurement was also confirmed against a `release-fast` build): - Before: ~260ms on average (in one run, it even took 600ms) - After: ~20ms on average Which reduces the time this method takes to load these by around ~92%. Given that we block on this during the initial app startup, this should drastically improve Zeds initial startup loading time. Yet, it also improves responsiveness when installing theme extensions and trying these. I also replaced all other `serde_json::from_reader` implementations with `serde_json::from_slice` and added the former to `disallowed_methods`, given https://github.com/serde-rs/json/issues/160#issuecomment-253446892. Release Notes: - Improved Zed startup speed when using themes provided by extensions
This commit is contained in:
@@ -50,7 +50,7 @@ use zed_perf::{FailKind, Importance, Output, TestMdata, Timings, consts};
|
||||
|
||||
use std::{
|
||||
fs::OpenOptions,
|
||||
io::Write,
|
||||
io::{Read, Write},
|
||||
num::NonZero,
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, Stdio},
|
||||
@@ -264,8 +264,14 @@ fn compare_profiles(args: &[String]) {
|
||||
let prefix = elems.next().unwrap();
|
||||
assert_eq!("json", elems.next().unwrap());
|
||||
assert!(elems.next().is_none());
|
||||
let handle = OpenOptions::new().read(true).open(entry.path()).unwrap();
|
||||
let o_other: Output = serde_json::from_reader(handle).unwrap();
|
||||
let mut buffer = Vec::new();
|
||||
let _ = OpenOptions::new()
|
||||
.read(true)
|
||||
.open(entry.path())
|
||||
.unwrap()
|
||||
.read_to_end(&mut buffer)
|
||||
.unwrap();
|
||||
let o_other: Output = serde_json::from_slice(&buffer).unwrap();
|
||||
output.merge(o_other, prefix);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user