mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-20 23:50:25 +01:00
Stop re-resolving editorconfig sections on every language settings lookup (#63323)
Closes https://github.com/zed-industries/zed/issues/59689
Symbolicating the reporter's profile (21s of typing, Windows) showed
`Window::draw` taking 63% of the main thread at ~62 redraws/s (p95 draw
= 40ms), and 30.9% of the *entire* main thread inside
`EditorconfigStore::properties()`:
every `LanguageSettings` lookup — several per frame via
`DisplayMap::tab_size`, `MultiBuffer::language_settings`, indent guides,
and `LspStore::supports_range_formatting` — re-ran the full editorconfig
resolution (ancestor walk plus `ec4rs::Section::apply_to` over every key
of every section) and then cloned the whole `LanguageSettings` struct.
Real-world `.editorconfig` files carry hundreds of irrelevant keys
(`dotnet_*`, `ij_*`, ...), so the per-call map assembly dominated:
`RtlAllocateHeap` 7.3%, `memcmp` 7.0%, `memcpy` 6.6%,
`Properties::find_idx` 5.9% self time.
## Commit 1: resolve only the editorconfig properties Zed reads
- `EditorconfigStore::properties()` now applies only the 7 keys Zed
consumes (`indent_style`, `indent_size`, `tab_width`, `end_of_line`,
`max_line_length`, `insert_final_newline`, `trim_trailing_whitespace`)
instead of materializing every key of every matching section.
- Worktrees with no editorconfig at all now return `None` early instead
of allocating an empty `Properties` and forcing a `LanguageSettings`
clone on every lookup.
- Adds an `editor_render_with_editorconfig` benchmark: maximized window,
file-backed buffer at `src/app/components/editor_pane.ts`, a root
`.editorconfig` shaped after [the second
report](https://github.com/zed-industries/zed/issues/59689#issuecomment-5475124891)
(no `root = true`, a `[*]` section with ~3200 keys, 25 sections with
large `{...}` alternation lists) plus a 4-level nested chain, and a
typing workload (insert/delete + cursor moves).
```
main (770aac345c): time: [37.905 ms 38.005 ms 38.107 ms]
time: [38.069 ms 38.157 ms 38.248 ms]
this commit: time: [2.8547 ms 2.8618 ms 2.8702 ms]
time: [2.8372 ms 2.8435 ms 2.8510 ms]
```
The candidate is ~13x faster.
GPUI frame report over the same workload: window draw p50 12.71 ms →
0.76 ms, p99 23.38 ms → 1.22 ms; frame budget overruns 556 → 0.
## Commit 2: cache resolved `LanguageSettings` per buffer
- `Buffer` and `BufferSnapshot` now hold `resolved_settings:
Arc<LanguageSettings>`, recomputed by a `SettingsStore` global observer.
- Global methods for retrieving the settings are still there, but buffer
only uses them for multi buffer's `language_settings_at` with an
injected language different from the buffer's primary; cold scopes such
as extension API, LSP workspace configuration, server startup still use
the global resolution
Same benchmark, same method, on top of commit 1 (alternated runs, quiet
machine):
```
commit 1: time: [2.8547 ms 2.8618 ms 2.8702 ms]
time: [2.8372 ms 2.8435 ms 2.8510 ms]
this commit: time: [1.6256 ms 1.6325 ms 1.6403 ms]
change: [-42.685% -42.270% -41.854%] (p = 0.00 < 0.05)
time: [1.6221 ms 1.6284 ms 1.6352 ms]
```
Window draw p50 0.76 ms → 0.47 ms, p99 1.22 ms → 0.69 ms, max 1.02 ms;
zero frame-budget overruns on both sides.
Combined, the benchmark's per-keystroke cost drops ~23x vs `main`
(37.9–38.2 ms → 1.62–1.64 ms).
Release Notes:
- Improved typing and rendering performance in projects that use
`.editorconfig` files.
This commit is contained in:
@@ -119,6 +119,7 @@ pub enum Event {
|
||||
Reloaded,
|
||||
CapabilityChanged,
|
||||
LanguageChanged(BufferId, bool),
|
||||
SettingsChanged,
|
||||
Reparsed(BufferId),
|
||||
Saved,
|
||||
FileHandleChanged,
|
||||
@@ -2039,6 +2040,7 @@ impl MultiBuffer {
|
||||
BufferEvent::LanguageChanged(has_language) => {
|
||||
Event::LanguageChanged(buffer_id, *has_language)
|
||||
}
|
||||
BufferEvent::SettingsChanged => Event::SettingsChanged,
|
||||
BufferEvent::Reparsed => Event::Reparsed(buffer_id),
|
||||
BufferEvent::DiagnosticsUpdated => Event::DiagnosticsUpdated,
|
||||
BufferEvent::CapabilityChanged => {
|
||||
@@ -2164,7 +2166,7 @@ impl MultiBuffer {
|
||||
.and_then(|(buffer, offset)| buffer.read(cx).language_at(offset))
|
||||
}
|
||||
|
||||
pub fn language_settings<'a>(&'a self, cx: &'a App) -> Cow<'a, LanguageSettings> {
|
||||
pub fn language_settings(&self, cx: &App) -> Arc<LanguageSettings> {
|
||||
let snapshot = self.snapshot(cx);
|
||||
snapshot
|
||||
.excerpts
|
||||
@@ -2174,15 +2176,11 @@ impl MultiBuffer {
|
||||
.unwrap_or_else(move || self.language_settings_at(MultiBufferOffset::default(), cx))
|
||||
}
|
||||
|
||||
pub fn language_settings_at<'a, T: ToOffset>(
|
||||
&'a self,
|
||||
point: T,
|
||||
cx: &'a App,
|
||||
) -> Cow<'a, LanguageSettings> {
|
||||
pub fn language_settings_at<T: ToOffset>(&self, point: T, cx: &App) -> Arc<LanguageSettings> {
|
||||
if let Some((buffer, offset)) = self.point_to_buffer_offset(point, cx) {
|
||||
LanguageSettings::for_buffer_at(buffer.read(cx), offset, cx)
|
||||
} else {
|
||||
Cow::Borrowed(&AllLanguageSettings::get_global(cx).defaults)
|
||||
AllLanguageSettings::get_global(cx).defaults.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6202,7 +6200,7 @@ impl MultiBufferSnapshot {
|
||||
.and_then(|(buffer, offset)| buffer.language_at(offset))
|
||||
}
|
||||
|
||||
fn language_settings<'a>(&'a self, cx: &'a App) -> Cow<'a, LanguageSettings> {
|
||||
fn language_settings(&self, cx: &App) -> Arc<LanguageSettings> {
|
||||
self.excerpts
|
||||
.first()
|
||||
.map(|excerpt| excerpt.buffer_snapshot(self))
|
||||
@@ -6210,15 +6208,11 @@ impl MultiBufferSnapshot {
|
||||
.unwrap_or_else(move || self.language_settings_at(MultiBufferOffset::ZERO, cx))
|
||||
}
|
||||
|
||||
pub fn language_settings_at<'a, T: ToOffset>(
|
||||
&'a self,
|
||||
point: T,
|
||||
cx: &'a App,
|
||||
) -> Cow<'a, LanguageSettings> {
|
||||
pub fn language_settings_at<T: ToOffset>(&self, point: T, cx: &App) -> Arc<LanguageSettings> {
|
||||
if let Some((buffer, offset)) = self.point_to_buffer_offset(point) {
|
||||
buffer.settings_at(offset, cx)
|
||||
} else {
|
||||
Cow::Borrowed(&AllLanguageSettings::get_global(cx).defaults)
|
||||
AllLanguageSettings::get_global(cx).defaults.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user