Query less inlay hints (#2842)

Part of
https://linear.app/zed-industries/issue/Z-2750/investigate-performance-of-collaborating-on-large-files-with-inlay

Instead of querying the entire file for hints, query visible editor(s)
range + the areas above and below, of the same height.
Non-invalidating future queries (e.g. scrolling) query only missing
parts of the ranges.

Release Notes:

- Improved LSP resource usage by querying less hints for big files
This commit is contained in:
Kirill Bulatov 2023-08-14 23:06:30 +03:00 committed by GitHub
commit 64c2043913
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 611 additions and 448 deletions

View file

@ -7953,7 +7953,8 @@ async fn test_mutual_editor_inlay_hint_cache_update(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, edits_made, inlay_cache.version(),
edits_made,
"Host editor update the cache version after every cache/view change", "Host editor update the cache version after every cache/view change",
); );
}); });
@ -7976,7 +7977,8 @@ async fn test_mutual_editor_inlay_hint_cache_update(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, edits_made, inlay_cache.version(),
edits_made,
"Guest editor update the cache version after every cache/view change" "Guest editor update the cache version after every cache/view change"
); );
}); });
@ -7996,7 +7998,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
"Host should get hints from the 1st edit and 1st LSP query" "Host should get hints from the 1st edit and 1st LSP query"
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version, edits_made); assert_eq!(inlay_cache.version(), edits_made);
}); });
editor_b.update(cx_b, |editor, _| { editor_b.update(cx_b, |editor, _| {
assert_eq!( assert_eq!(
@ -8010,7 +8012,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
"Guest should get hints the 1st edit and 2nd LSP query" "Guest should get hints the 1st edit and 2nd LSP query"
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version, edits_made); assert_eq!(inlay_cache.version(), edits_made);
}); });
editor_a.update(cx_a, |editor, cx| { editor_a.update(cx_a, |editor, cx| {
@ -8035,7 +8037,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
4th query was made by guest (but not applied) due to cache invalidation logic" 4th query was made by guest (but not applied) due to cache invalidation logic"
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version, edits_made); assert_eq!(inlay_cache.version(), edits_made);
}); });
editor_b.update(cx_b, |editor, _| { editor_b.update(cx_b, |editor, _| {
assert_eq!( assert_eq!(
@ -8051,7 +8053,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
"Guest should get hints from 3rd edit, 6th LSP query" "Guest should get hints from 3rd edit, 6th LSP query"
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!(inlay_cache.version, edits_made); assert_eq!(inlay_cache.version(), edits_made);
}); });
fake_language_server fake_language_server
@ -8077,7 +8079,8 @@ async fn test_mutual_editor_inlay_hint_cache_update(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, edits_made, inlay_cache.version(),
edits_made,
"Host should accepted all edits and bump its cache version every time" "Host should accepted all edits and bump its cache version every time"
); );
}); });
@ -8098,7 +8101,7 @@ async fn test_mutual_editor_inlay_hint_cache_update(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, inlay_cache.version(),
edits_made, edits_made,
"Guest should accepted all edits and bump its cache version every time" "Guest should accepted all edits and bump its cache version every time"
); );
@ -8264,7 +8267,8 @@ async fn test_inlay_hint_refresh_is_forwarded(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, 0, inlay_cache.version(),
0,
"Host should not increment its cache version due to no changes", "Host should not increment its cache version due to no changes",
); );
}); });
@ -8279,7 +8283,8 @@ async fn test_inlay_hint_refresh_is_forwarded(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, edits_made, inlay_cache.version(),
edits_made,
"Guest editor update the cache version after every cache/view change" "Guest editor update the cache version after every cache/view change"
); );
}); });
@ -8296,7 +8301,8 @@ async fn test_inlay_hint_refresh_is_forwarded(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, 0, inlay_cache.version(),
0,
"Host should not increment its cache version due to no changes", "Host should not increment its cache version due to no changes",
); );
}); });
@ -8311,7 +8317,8 @@ async fn test_inlay_hint_refresh_is_forwarded(
); );
let inlay_cache = editor.inlay_hint_cache(); let inlay_cache = editor.inlay_hint_cache();
assert_eq!( assert_eq!(
inlay_cache.version, edits_made, inlay_cache.version(),
edits_made,
"Guest should accepted all edits and bump its cache version every time" "Guest should accepted all edits and bump its cache version every time"
); );
}); });
@ -8343,13 +8350,10 @@ fn room_participants(room: &ModelHandle<Room>, cx: &mut TestAppContext) -> RoomP
fn extract_hint_labels(editor: &Editor) -> Vec<String> { fn extract_hint_labels(editor: &Editor) -> Vec<String> {
let mut labels = Vec::new(); let mut labels = Vec::new();
for (_, excerpt_hints) in &editor.inlay_hint_cache().hints { for hint in editor.inlay_hint_cache().hints() {
let excerpt_hints = excerpt_hints.read(); match hint.label {
for (_, inlay) in excerpt_hints.hints.iter() { project::InlayHintLabel::String(s) => labels.push(s),
match &inlay.label { _ => unreachable!(),
project::InlayHintLabel::String(s) => labels.push(s.to_string()),
_ => unreachable!(),
}
} }
} }
labels labels

View file

@ -2723,7 +2723,7 @@ impl Editor {
.collect() .collect()
} }
fn excerpt_visible_offsets( pub fn excerpt_visible_offsets(
&self, &self,
restrict_to_languages: Option<&HashSet<Arc<Language>>>, restrict_to_languages: Option<&HashSet<Arc<Language>>>,
cx: &mut ViewContext<'_, '_, Editor>, cx: &mut ViewContext<'_, '_, Editor>,

File diff suppressed because it is too large Load diff

View file

@ -13,7 +13,7 @@ use gpui::{
}; };
use language::{Bias, Point}; use language::{Bias, Point};
use util::ResultExt; use util::ResultExt;
use workspace::{item::Item, WorkspaceId}; use workspace::WorkspaceId;
use crate::{ use crate::{
display_map::{DisplaySnapshot, ToDisplayPoint}, display_map::{DisplaySnapshot, ToDisplayPoint},
@ -333,9 +333,7 @@ impl Editor {
cx, cx,
); );
if !self.is_singleton(cx) { self.refresh_inlays(InlayRefreshReason::NewLinesShown, cx);
self.refresh_inlays(InlayRefreshReason::NewLinesShown, cx);
}
} }
pub fn scroll_position(&self, cx: &mut ViewContext<Self>) -> Vector2F { pub fn scroll_position(&self, cx: &mut ViewContext<Self>) -> Vector2F {