Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
42f6cb0
Work in progress
Anthony-Eid May 31, 2026
9c57459
Update plan
Anthony-Eid May 31, 2026
555ad2c
Add bench macros
Anthony-Eid Jun 1, 2026
47fe6e7
Add back removed benches
Anthony-Eid Jun 1, 2026
9b7a28c
Remove plan doc
Anthony-Eid Jun 1, 2026
59c98b1
Merge branch 'main' into bench-app-context
Anthony-Eid Jun 1, 2026
4fbfd63
integrate criterion into BenchAppContext and create render bench
Anthony-Eid Jun 1, 2026
47024b8
Deeper integration
Anthony-Eid Jun 1, 2026
c6a1eee
merge conflicts
Anthony-Eid Jun 2, 2026
2b677ed
fix bad merge conflict
Anthony-Eid Jun 2, 2026
f39ddda
Remove feature flags
Anthony-Eid Jun 2, 2026
65d78b8
more clean up
Anthony-Eid Jun 2, 2026
b08d202
Merge remote-tracking branch 'origin' into bench-app-context-phase-2
Anthony-Eid Jun 2, 2026
496109d
Allow passing in frame budget
Anthony-Eid Jun 2, 2026
5535f61
Fix clippy
Anthony-Eid Jun 2, 2026
c051bf8
Fix build errors
Anthony-Eid Jun 2, 2026
7f0c06d
Fix clippy
Anthony-Eid Jun 2, 2026
deb2235
Use histogram for outputs
Anthony-Eid Jun 3, 2026
0e71c97
clean up
Anthony-Eid Jun 3, 2026
df970b1
Merge branch 'main' into bench-app-context-phase-2
Anthony-Eid Jun 3, 2026
b5016de
remove warnings
Anthony-Eid Jun 6, 2026
e05d899
Move more collections to profiler
Anthony-Eid Jun 9, 2026
fa702f7
Clean ups
Anthony-Eid Jun 9, 2026
81db4e5
More clean up
Anthony-Eid Jun 9, 2026
68f723f
Clean up
Anthony-Eid Jun 9, 2026
b83efc1
Fix some multi threaded teardown/setup race conditions
Anthony-Eid Jun 10, 2026
2713a28
Move benches to benchmark crate to avoid having gpui_platform dev import
Anthony-Eid Jun 10, 2026
b9b0f11
Fix clippy
Anthony-Eid Jun 10, 2026
3030d78
Merge remote-tracking branch 'origin' into bench-app-context-phase-2
Anthony-Eid Jun 10, 2026
cc4359a
Add LICENSE-GPL symlink to benchmarks crate
Anthony-Eid Jun 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"crates/auto_update_ui",
"crates/aws_http_client",
"crates/bedrock",
"crates/benchmarks",
"crates/breadcrumbs",
"crates/buffer_diff",
"crates/call",
Expand Down
6 changes: 0 additions & 6 deletions crates/agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ agent_servers = { workspace = true, "features" = ["test-support"] }
client = { workspace = true, "features" = ["test-support"] }
clock = { workspace = true, "features" = ["test-support"] }
context_server = { workspace = true, "features" = ["test-support"] }
criterion.workspace = true
ctor.workspace = true
db = { workspace = true, "features" = ["test-support"] }
editor = { workspace = true, "features" = ["test-support"] }
Expand All @@ -110,8 +109,3 @@ theme_settings.workspace = true
unindent = { workspace = true }

zlog.workspace = true

[[bench]]
name = "edit_file_tool"
harness = false
required-features = ["test-support"]
52 changes: 52 additions & 0 deletions crates/benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "benchmarks"
version = "0.1.0"
edition.workspace = true
publish.workspace = true
license = "GPL-3.0-or-later"

[lib]
path = "src/benchmarks.rs"
doctest = false

[lints]
workspace = true

[dev-dependencies]
action_log.workspace = true
agent = { workspace = true, features = ["test-support"] }
agent_settings.workspace = true
assets.workspace = true
criterion.workspace = true
editor = { workspace = true, features = ["test-support"] }
futures.workspace = true
gpui = { workspace = true, features = ["bench"] }
gpui_platform = { workspace = true, features = ["test-support"] }
itertools.workspace = true
language = { workspace = true, features = ["test-support"] }
language_model = { workspace = true, features = ["test-support"] }
lsp = { workspace = true, features = ["test-support"] }
multi_buffer.workspace = true
project = { workspace = true, features = ["test-support"] }
prompt_store.workspace = true
rand.workspace = true
serde_json.workspace = true
settings = { workspace = true, features = ["test-support"] }
text.workspace = true
theme = { workspace = true, features = ["test-support"] }
theme_settings.workspace = true
ui.workspace = true
util = { workspace = true, features = ["test-support"] }
zed_actions.workspace = true

[[bench]]
name = "editor_render"
harness = false

[[bench]]
name = "display_map"
harness = false

[[bench]]
name = "edit_file_tool"
harness = false
1 change: 1 addition & 0 deletions crates/benchmarks/LICENSE-GPL
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use editor::{
use gpui::{AppContext as _, BenchAppContext, Focusable as _, TestAppContext, TestDispatcher};
use rand::{Rng as _, SeedableRng as _, rngs::StdRng};
use settings::SettingsStore;
use ui::IntoElement;
use util::RandomCharIter;
use zed_actions::editor::{MoveDown, MoveUp};

#[gpui::bench]
fn editor_input_with_1000_cursors(bencher: &mut Bencher<'_>, cx: &mut BenchAppContext) {
fn editor_input_with_1000_cursors(cx: &mut BenchAppContext) {
init_context(cx);

let text = String::from_iter(["line:\n"; 1000]);
let buffer = cx.update(|cx| MultiBuffer::build_simple(&text, cx));

let mut cx = cx.add_empty_window();
let editor = cx.update(|window, cx| {
let mut window = cx.add_empty_window();
let editor = window.update(|window, cx| {
let editor = cx.new(|cx| {
let mut editor = Editor::new(EditorMode::full(), buffer, None, window, cx);
editor.set_style(editor::EditorStyle::default(), window, cx);
Expand All @@ -35,8 +35,8 @@ fn editor_input_with_1000_cursors(bencher: &mut Bencher<'_>, cx: &mut BenchAppCo
editor
});

bencher.iter(|| {
cx.update(|window, cx| {
cx.bench_iter(|_| {
window.update(|window, cx| {
editor.update(cx, |editor, cx| {
editor.handle_input("hello world", window, cx);
editor.delete_to_previous_word_start(
Expand Down Expand Up @@ -80,8 +80,10 @@ fn open_editor_with_one_long_line(bencher: &mut Bencher<'_>, args: &(String, Tes
});
}

fn editor_render(bencher: &mut Bencher<'_>, cx: &TestAppContext) {
let mut cx = cx.clone();
#[gpui::bench]
fn editor_render(cx: &mut BenchAppContext) {
init_context(cx);

let buffer = cx.update(|cx| {
let mut rng = StdRng::seed_from_u64(1);
let text_len = rng.random_range(10000..90000);
Expand All @@ -95,9 +97,9 @@ fn editor_render(bencher: &mut Bencher<'_>, cx: &TestAppContext) {
}
});

let cx = cx.add_empty_window();
let editor = cx.update(|window, cx| {
let editor = cx.new(|cx| {
let mut window = cx.add_empty_window();
let editor = window.update(|window, cx| {
let editor = window.replace_root(cx, |window, cx| {
let mut editor = Editor::new(EditorMode::full(), buffer, None, window, cx);
editor.set_style(editor::EditorStyle::default(), window, cx);
editor
Expand All @@ -106,14 +108,15 @@ fn editor_render(bencher: &mut Bencher<'_>, cx: &TestAppContext) {
editor
});

bencher.iter(|| {
cx.update(|window, cx| {
let mut view = editor.clone().into_any_element();
let _ = view.request_layout(window, cx);
let _ = view.prepaint(window, cx);
view.paint(window, cx);
});
})
let mut move_down = true;
cx.bench_renderer(editor, move |editor, window, cx| {
if move_down {
editor.move_down(&MoveDown, window, cx);
} else {
editor.move_up(&MoveUp, window, cx);
}
move_down = !move_down;
});
}

fn init_context(cx: &mut BenchAppContext) {
Expand Down Expand Up @@ -141,16 +144,8 @@ fn criterion_benches(criterion: &mut criterion::Criterion) {
let cx = gpui::TestAppContext::build(dispatcher, None);
init_test_context(&cx);

let mut group = criterion.benchmark_group("Time to render");
group.bench_with_input(
BenchmarkId::new("editor_render", "TestAppContext"),
&cx,
editor_render,
);
group.finish();

let text = String::from_iter(["char"; 1000]);
let input = (text, cx.clone());
let input = (text, cx);
let mut group = criterion.benchmark_group("Build buffer with one long line");
group.bench_with_input(
BenchmarkId::new("editor_with_one_long_line", "(String, TestAppContext )"),
Expand All @@ -160,5 +155,10 @@ fn criterion_benches(criterion: &mut criterion::Criterion) {
group.finish();
}

gpui::bench_group!(benches, editor_input_with_1000_cursors, criterion_benches);
gpui::bench_group!(
benches,
editor_input_with_1000_cursors,
editor_render,
criterion_benches
);
gpui::bench_main!(benches);
6 changes: 6 additions & 0 deletions crates/benchmarks/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//! Benchmark targets for Zed crates.
//!
//! Benchmarks live in their own crate so benchmark-only dependencies
//! (Criterion, `gpui_platform`, gpui's `bench` feature, ...) don't weigh down
//! the test builds of the crates being benchmarked. Each file in `benches/`
//! targets one area of the codebase.
10 changes: 0 additions & 10 deletions crates/editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ zed_actions.workspace = true
zlog.workspace = true

[dev-dependencies]
criterion.workspace = true
ctor.workspace = true
gpui = { workspace = true, features = ["test-support"] }
language = { workspace = true, features = ["test-support"] }
Expand Down Expand Up @@ -138,12 +137,3 @@ util = { workspace = true, features = ["test-support"] }
workspace = { workspace = true, features = ["test-support"] }

zlog.workspace = true


[[bench]]
name = "editor_render"
harness = false

[[bench]]
name = "display_map"
harness = false
2 changes: 2 additions & 0 deletions crates/gpui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test-support = [
"x11",
"proptest",
]
bench = ["test-support", "dep:criterion", "dep:hdrhistogram"]
inspector = ["gpui_macros/inspector"]
leak-detection = ["backtrace"]
wayland = [
Expand Down Expand Up @@ -53,6 +54,7 @@ backtrace = { workspace = true, optional = true }
bitflags = { workspace = true, optional = true }

collections.workspace = true
criterion = { workspace = true, optional = true }
ctor.workspace = true
derive_more.workspace = true
etagere = "0.2"
Expand Down
8 changes: 4 additions & 4 deletions crates/gpui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use parking_lot::RwLock;
use slotmap::SlotMap;

pub use async_context::*;
#[cfg(any(test, feature = "test-support"))]
pub use bench_context::{BenchAppContext, BenchWindowContext};
#[cfg(feature = "bench")]
pub use bench_context::{BenchAppContext, BenchReport, BenchWindowContext, bench_platform};
use collections::{FxHashMap, FxHashSet, HashMap, TypeIdHashMap, TypeIdHashSet, VecDeque};
pub use context::*;
pub use entity_map::*;
Expand Down Expand Up @@ -58,7 +58,7 @@ use crate::{
};

mod async_context;
#[cfg(any(test, feature = "test-support"))]
#[cfg(feature = "bench")]
mod bench_context;
mod context;
mod entity_map;
Expand Down Expand Up @@ -1489,7 +1489,7 @@ impl App {
}
}
} else {
#[cfg(any(test, feature = "test-support"))]
#[cfg(any(test, feature = "test-support", feature = "bench"))]
for window in self
.windows
.values()
Expand Down
Loading
Loading