Parallelize deserialization of pane items on startup

Co-Authored-By: Mikayla Maki <mikayla@zed.dev>
This commit is contained in:
Antonio Scandurra 2024-01-23 19:34:10 +01:00
parent 526ea40005
commit e4604ebedf

View file

@ -233,24 +233,28 @@ impl SerializedPane {
workspace: WeakView<Workspace>,
cx: &mut AsyncWindowContext,
) -> Result<Vec<Option<Box<dyn ItemHandle>>>> {
let mut items = Vec::new();
let mut item_tasks = Vec::new();
let mut active_item_index = None;
for (index, item) in self.children.iter().enumerate() {
let project = project.clone();
let item_handle = pane
.update(cx, |_, cx| {
if let Some(deserializer) = cx.global::<ItemDeserializers>().get(&item.kind) {
deserializer(project, workspace.clone(), workspace_id, item.item_id, cx)
} else {
Task::ready(Err(anyhow::anyhow!(
"Deserializer does not exist for item kind: {}",
item.kind
)))
}
})?
.await
.log_err();
item_tasks.push(pane.update(cx, |_, cx| {
if let Some(deserializer) = cx.global::<ItemDeserializers>().get(&item.kind) {
deserializer(project, workspace.clone(), workspace_id, item.item_id, cx)
} else {
Task::ready(Err(anyhow::anyhow!(
"Deserializer does not exist for item kind: {}",
item.kind
)))
}
})?);
if item.active {
active_item_index = Some(index);
}
}
let mut items = Vec::new();
for item_handle in futures::future::join_all(item_tasks).await {
let item_handle = item_handle.log_err();
items.push(item_handle.clone());
if let Some(item_handle) = item_handle {
@ -258,10 +262,6 @@ impl SerializedPane {
pane.add_item(item_handle.clone(), true, true, None, cx);
})?;
}
if item.active {
active_item_index = Some(index);
}
}
if let Some(active_item_index) = active_item_index {