Reduce amount of foreground tasks spawned on multibuffer/editor updates (#41479)
When doing a project wide search in zed on windows for `hang`, zed starts to freeze for a couple seconds ultimately starting to error with `Not enough quota is available to process this command.` when dispatching windows messages. The cause for this is that we simply overload the windows message pump due to the sheer amount of foreground tasks we spawn when we populate the project search. This PR is an attempt at reducing this. Release Notes: - Reduced hangs and stutters in large project file searches
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::{mem, ops::Range, sync::Arc};
|
||||
|
||||
use collections::HashSet;
|
||||
use gpui::{App, AppContext, Context, Entity, Task};
|
||||
use gpui::{App, AppContext, Context, Entity};
|
||||
use itertools::Itertools;
|
||||
use language::{Buffer, BufferSnapshot};
|
||||
use rope::Point;
|
||||
@@ -117,12 +117,14 @@ impl MultiBuffer {
|
||||
buffer: Entity<Buffer>,
|
||||
ranges: Vec<Range<text::Anchor>>,
|
||||
context_line_count: u32,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Vec<Range<Anchor>>> {
|
||||
cx: &Context<Self>,
|
||||
) -> impl Future<Output = Vec<Range<Anchor>>> + use<> {
|
||||
let buffer_snapshot = buffer.read(cx).snapshot();
|
||||
cx.spawn(async move |multi_buffer, cx| {
|
||||
let multi_buffer = cx.weak_entity();
|
||||
let mut app = cx.to_async();
|
||||
async move {
|
||||
let snapshot = buffer_snapshot.clone();
|
||||
let (excerpt_ranges, new, counts) = cx
|
||||
let (excerpt_ranges, new, counts) = app
|
||||
.background_spawn(async move {
|
||||
let ranges = ranges.into_iter().map(|range| range.to_point(&snapshot));
|
||||
let excerpt_ranges =
|
||||
@@ -133,7 +135,7 @@ impl MultiBuffer {
|
||||
.await;
|
||||
|
||||
multi_buffer
|
||||
.update(cx, move |multi_buffer, cx| {
|
||||
.update(&mut app, move |multi_buffer, cx| {
|
||||
let (ranges, _) = multi_buffer.set_merged_excerpt_ranges_for_path(
|
||||
path_key,
|
||||
buffer,
|
||||
@@ -147,7 +149,7 @@ impl MultiBuffer {
|
||||
})
|
||||
.ok()
|
||||
.unwrap_or_default()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn expand_excerpts_with_paths(
|
||||
|
||||
Reference in New Issue
Block a user