Skip to repository content152 lines · 4.7 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T05:10:10.929Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
editor_render.rs
1use editor::{
2 Editor, EditorMode, MultiBuffer,
3 actions::{DeleteToPreviousWordStart, SelectAll, SplitSelectionIntoLines},
4};
5use gpui::{AppContext as _, BenchAppContext, Focusable as _};
6use rand::{Rng as _, SeedableRng as _, rngs::StdRng};
7use settings::SettingsStore;
8use util::RandomCharIter;
9use zed_actions::editor::{MoveDown, MoveUp};
10
11#[gpui::bench(
12 inputs = multi_cursor_line_counts(),
13 group = "Multi-cursor input",
14 input_name = "cursors",
15 sample_size = 10
16)]
17fn editor_multi_cursor_input(line_count: &usize, cx: &mut BenchAppContext) {
18 init_context(cx);
19
20 let text = "line:\n".repeat(*line_count);
21 let buffer = cx.update(|cx| MultiBuffer::build_simple(&text, cx));
22
23 let mut window = cx.add_empty_window();
24 let editor = window.update(|window, cx| {
25 let editor = cx.new(|cx| {
26 let mut editor = Editor::new(EditorMode::full(), buffer, None, window, cx);
27 editor.set_style(editor::EditorStyle::default(), window, cx);
28 editor.select_all(&SelectAll, window, cx);
29 editor.split_selection_into_lines(
30 &SplitSelectionIntoLines {
31 keep_selections: true,
32 },
33 window,
34 cx,
35 );
36 editor
37 });
38 window.focus(&editor.focus_handle(cx), cx);
39 editor
40 });
41
42 cx.bench_iter(|_| {
43 window.update(|window, cx| {
44 editor.update(cx, |editor, cx| {
45 editor.handle_input("hello world", window, cx);
46 editor.delete_to_previous_word_start(
47 &DeleteToPreviousWordStart {
48 ignore_newlines: false,
49 ignore_brackets: false,
50 },
51 window,
52 cx,
53 );
54 editor.delete_to_previous_word_start(
55 &DeleteToPreviousWordStart {
56 ignore_newlines: false,
57 ignore_brackets: false,
58 },
59 window,
60 cx,
61 );
62 });
63 })
64 });
65}
66
67#[gpui::bench]
68fn open_editor_with_one_long_line(cx: &mut BenchAppContext) {
69 init_context(cx);
70
71 let text = String::from_iter(["char"; 1000]);
72 cx.bench_iter(move |cx| {
73 let buffer = cx.update(|cx| MultiBuffer::build_simple(&text, cx));
74
75 let mut window = cx.add_empty_window();
76 window.update(|window, cx| {
77 let editor = cx.new(|cx| {
78 let mut editor = Editor::new(EditorMode::full(), buffer, None, window, cx);
79 editor.set_style(editor::EditorStyle::default(), window, cx);
80 editor
81 });
82 window.focus(&editor.focus_handle(cx), cx);
83 editor
84 });
85 });
86}
87
88#[gpui::bench]
89fn editor_render(cx: &mut BenchAppContext) {
90 init_context(cx);
91
92 let buffer = cx.update(|cx| {
93 let mut rng = StdRng::seed_from_u64(1);
94 let text_len = rng.random_range(10000..90000);
95 if rng.random() {
96 let text = RandomCharIter::new(&mut rng)
97 .take(text_len)
98 .collect::<String>();
99 MultiBuffer::build_simple(&text, cx)
100 } else {
101 MultiBuffer::build_random(&mut rng, cx)
102 }
103 });
104
105 let mut window = cx.add_empty_window();
106 let editor = window.update(|window, cx| {
107 let editor = window.replace_root(cx, |window, cx| {
108 let mut editor = Editor::new(EditorMode::full(), buffer, None, window, cx);
109 editor.set_style(editor::EditorStyle::default(), window, cx);
110 editor
111 });
112 window.focus(&editor.focus_handle(cx), cx);
113 editor
114 });
115
116 let mut move_down = true;
117 cx.bench_renderer(editor, move |editor, window, cx| {
118 if move_down {
119 editor.move_down(&MoveDown, window, cx);
120 } else {
121 editor.move_up(&MoveUp, window, cx);
122 }
123 move_down = !move_down;
124 });
125}
126
127fn init_context(cx: &mut BenchAppContext) {
128 cx.update(|cx| {
129 let store = SettingsStore::test(cx);
130 cx.set_global(store);
131 assets::Assets.load_test_fonts(cx);
132 theme_settings::init(theme::LoadThemes::JustBase, cx);
133 editor::init(cx);
134 });
135}
136
137fn multi_cursor_line_counts() -> Vec<usize> {
138 let mut line_counts = vec![1000, 10000];
139 if std::env::var("ZED_BENCH_HUGE").is_ok() {
140 line_counts.push(100000);
141 }
142 line_counts
143}
144
145gpui::bench_group!(
146 benches,
147 editor_multi_cursor_input,
148 open_editor_with_one_long_line,
149 editor_render
150);
151gpui::bench_main!(benches);
152