diff --git a/Cargo.lock b/Cargo.lock index 9663b5c6c0..06c3d1e99a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4697,6 +4697,7 @@ dependencies = [ "clock", "collections", "convert_case 0.8.0", + "criterion", "ctor", "dap", "db", diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index bc901fece3..ff8026c3c0 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -92,6 +92,7 @@ zed_actions.workspace = true workspace-hack.workspace = true [dev-dependencies] +criterion.workspace = true ctor.workspace = true gpui = { workspace = true, features = ["test-support"] } language = { workspace = true, features = ["test-support"] } @@ -114,3 +115,8 @@ util = { workspace = true, features = ["test-support"] } workspace = { workspace = true, features = ["test-support"] } http_client = { workspace = true, features = ["test-support"] } zlog.workspace = true + + +[[bench]] +name = "editor_render" +harness = false diff --git a/crates/editor/benches/editor_render.rs b/crates/editor/benches/editor_render.rs new file mode 100644 index 0000000000..d208889950 --- /dev/null +++ b/crates/editor/benches/editor_render.rs @@ -0,0 +1,89 @@ +use criterion::{ + BatchSize, Bencher, BenchmarkId, Criterion, Throughput, black_box, criterion_group, + criterion_main, +}; +use editor::{Editor, EditorElement, EditorMode, EditorSettings, MultiBuffer}; +use gpui::{AppContext, Focusable as _, Render, TestAppContext, TestDispatcher}; +use project::Project; +use rand::{Rng as _, SeedableRng as _, rngs::StdRng}; +use settings::{Settings, SettingsStore}; +use ui::{Element, IntoElement}; +use util::RandomCharIter; + +fn editor_render(bencher: &mut Bencher<'_>, cx: &TestAppContext) { + let mut cx = cx.clone(); + let buffer = cx.update(|cx| { + let mut rng = StdRng::seed_from_u64(1); + let text_len = rng.gen_range(10000..100000); + if rng.r#gen() { + let text = RandomCharIter::new(&mut rng) + .take(text_len) + .collect::(); + MultiBuffer::build_simple(&text, cx) + } else { + MultiBuffer::build_random(&mut rng, cx) + } + }); + + let cx = cx.add_empty_window(); + let mut editor = cx.update(|window, cx| { + let editor = cx.new(|cx| Editor::new(EditorMode::full(), buffer, None, window, cx)); + window.focus(&editor.focus_handle(cx)); + editor + }); + + bencher.iter(|| { + cx.update(|window, cx| { + let (_, mut layout_state) = editor.request_layout(None, None, window, cx); + let mut prepaint = + editor.prepaint(None, None, window.bounds(), &mut layout_state, window, cx); + editor.paint( + None, + None, + window.bounds(), + &mut layout_state, + &mut prepaint, + window, + cx, + ); + + window.refresh(); + }); + }) +} + +pub fn benches() { + let dispatcher = TestDispatcher::new(StdRng::seed_from_u64(1)); + let cx = gpui::TestAppContext::build(dispatcher, None); + cx.update(|cx| { + let store = SettingsStore::test(cx); + cx.set_global(store); + assets::Assets.load_test_fonts(cx); + theme::init(theme::LoadThemes::JustBase, cx); + // release_channel::init(SemanticVersion::default(), cx); + client::init_settings(cx); + language::init(cx); + workspace::init_settings(cx); + Project::init_settings(cx); + editor::init(cx); + }); + + let mut criterion: criterion::Criterion<_> = + (criterion::Criterion::default()).configure_from_args(); + + cx.dispatch_keystroke(window, keystroke); + + // setup app context + criterion.bench_with_input( + BenchmarkId::new("editor_render", "TestAppContext"), + &cx, + |bencher, cx| editor_render(bencher, cx), + ); +} + +fn main() { + benches(); + criterion::Criterion::default() + .configure_from_args() + .final_summary(); +} diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index 0291471c6f..c39f0ba49e 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -7734,7 +7734,7 @@ impl<'a> Iterator for MultiBufferChunks<'a> { }) } else { self.range.start = chunk_end; - dbg!(self.buffer_chunk.take()) + self.buffer_chunk.take() } } DiffTransform::DeletedHunk {