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:
@@ -408,8 +408,8 @@ impl Theme {
|
||||
|
||||
/// Asynchronously reads the user theme from the specified path.
|
||||
pub async fn read_user_theme(theme_path: &Path, fs: Arc<dyn Fs>) -> Result<ThemeFamilyContent> {
|
||||
let reader = fs.open_sync(theme_path).await?;
|
||||
let theme_family: ThemeFamilyContent = serde_json_lenient::from_reader(reader)?;
|
||||
let bytes = fs.load_bytes(theme_path).await?;
|
||||
let theme_family: ThemeFamilyContent = serde_json_lenient::from_slice(&bytes)?;
|
||||
|
||||
for theme in &theme_family.themes {
|
||||
if theme
|
||||
@@ -433,8 +433,8 @@ pub async fn read_icon_theme(
|
||||
icon_theme_path: &Path,
|
||||
fs: Arc<dyn Fs>,
|
||||
) -> Result<IconThemeFamilyContent> {
|
||||
let reader = fs.open_sync(icon_theme_path).await?;
|
||||
let icon_theme_family: IconThemeFamilyContent = serde_json_lenient::from_reader(reader)?;
|
||||
let bytes = fs.load_bytes(icon_theme_path).await?;
|
||||
let icon_theme_family: IconThemeFamilyContent = serde_json_lenient::from_slice(&bytes)?;
|
||||
|
||||
Ok(icon_theme_family)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user