mirror of
https://github.com/zed-industries/zed.git
synced 2026-06-01 03:14:56 +07:00
git_ui: Introduce explicit yield points for project diff (#43706)
These are long running foreground tasks that tend to not have pending await points, meaning once we start executing them they will never reschedule themselves, starving the foreground thread. Release Notes: - Improved git project diff responsiveness
This commit is contained in:
parent
f856a3ca89
commit
fc213f1c26
4 changed files with 17 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -7129,6 +7129,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_json",
|
||||
"settings",
|
||||
"smol",
|
||||
"strum 0.27.2",
|
||||
"telemetry",
|
||||
"theme",
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ schemars.workspace = true
|
|||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
settings.workspace = true
|
||||
smol.workspace = true
|
||||
strum.workspace = true
|
||||
telemetry.workspace = true
|
||||
theme.workspace = true
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ use project::{
|
|||
},
|
||||
};
|
||||
use settings::{Settings, SettingsStore};
|
||||
use smol::future::yield_now;
|
||||
use std::any::{Any, TypeId};
|
||||
use std::ops::Range;
|
||||
use std::sync::Arc;
|
||||
|
|
@ -584,6 +585,9 @@ impl ProjectDiff {
|
|||
|
||||
for (entry, path_key) in buffers_to_load.into_iter().zip(path_keys.into_iter()) {
|
||||
if let Some((buffer, diff)) = entry.load.await.log_err() {
|
||||
// We might be lagging behind enough that all future entry.load futures are no longer pending.
|
||||
// If that is the case, this task will never yield, starving the foreground thread of execution time.
|
||||
yield_now().await;
|
||||
cx.update(|window, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
this.register_buffer(path_key, entry.file_status, buffer, diff, window, cx)
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ use rpc::{
|
|||
};
|
||||
use serde::Deserialize;
|
||||
use settings::WorktreeId;
|
||||
use smol::future::yield_now;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
collections::{BTreeSet, HashSet, VecDeque},
|
||||
|
|
@ -2984,6 +2985,10 @@ impl BufferGitState {
|
|||
);
|
||||
}
|
||||
|
||||
// Dropping BufferDiff can be expensive, so yield back to the event loop
|
||||
// for a bit
|
||||
yield_now().await;
|
||||
|
||||
let mut new_uncommitted_diff = None;
|
||||
if let Some(uncommitted_diff) = &uncommitted_diff {
|
||||
new_uncommitted_diff = if index_matches_head {
|
||||
|
|
@ -3005,6 +3010,10 @@ impl BufferGitState {
|
|||
}
|
||||
}
|
||||
|
||||
// Dropping BufferDiff can be expensive, so yield back to the event loop
|
||||
// for a bit
|
||||
yield_now().await;
|
||||
|
||||
let cancel = this.update(cx, |this, _| {
|
||||
// This checks whether all pending stage/unstage operations
|
||||
// have quiesced (i.e. both the corresponding write and the
|
||||
|
|
@ -3043,6 +3052,8 @@ impl BufferGitState {
|
|||
None
|
||||
};
|
||||
|
||||
yield_now().await;
|
||||
|
||||
if let Some((uncommitted_diff, new_uncommitted_diff)) =
|
||||
uncommitted_diff.as_ref().zip(new_uncommitted_diff.clone())
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue