Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T05:15:42.662Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

highlight_map.rs

145 lines · 3.6 KB · rust
1use criterion::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main};
2use gpui::rgba;
3use language::build_highlight_map;
4use theme::SyntaxTheme;
5
6fn syntax_theme(highlight_names: &[&str]) -> SyntaxTheme {
7    SyntaxTheme::new(highlight_names.iter().enumerate().map(|(i, name)| {
8        let r = ((i * 37) % 256) as u8;
9        let g = ((i * 53) % 256) as u8;
10        let b = ((i * 71) % 256) as u8;
11        let color = rgba(u32::from_be_bytes([r, g, b, 0xff]));
12        (name.to_string(), color.into())
13    }))
14}
15
16static SMALL_THEME_KEYS: &[&str] = &[
17    "comment", "function", "keyword", "string", "type", "variable",
18];
19
20static LARGE_THEME_KEYS: &[&str] = &[
21    "attribute",
22    "boolean",
23    "comment",
24    "comment.doc",
25    "constant",
26    "constant.builtin",
27    "constructor",
28    "embedded",
29    "emphasis",
30    "emphasis.strong",
31    "function",
32    "function.builtin",
33    "function.method",
34    "function.method.builtin",
35    "function.special.definition",
36    "keyword",
37    "keyword.control",
38    "keyword.control.conditional",
39    "keyword.control.import",
40    "keyword.control.repeat",
41    "keyword.control.return",
42    "keyword.modifier",
43    "keyword.operator",
44    "label",
45    "link_text",
46    "link_uri",
47    "number",
48    "operator",
49    "property",
50    "punctuation",
51    "punctuation.bracket",
52    "punctuation.delimiter",
53    "punctuation.list_marker",
54    "punctuation.special",
55    "string",
56    "string.escape",
57    "string.regex",
58    "string.special",
59    "string.special.symbol",
60    "tag",
61    "text.literal",
62    "title",
63    "type",
64    "type.builtin",
65    "type.super",
66    "variable",
67    "variable.builtin",
68    "variable.member",
69    "variable.parameter",
70    "variable.special",
71];
72
73static SMALL_CAPTURE_NAMES: &[&str] = &[
74    "function",
75    "keyword",
76    "string.escape",
77    "type.builtin",
78    "variable.builtin",
79];
80
81static LARGE_CAPTURE_NAMES: &[&str] = &[
82    "attribute",
83    "boolean",
84    "comment",
85    "comment.doc",
86    "constant",
87    "constant.builtin",
88    "constructor",
89    "function",
90    "function.builtin",
91    "function.method",
92    "keyword",
93    "keyword.control",
94    "keyword.control.conditional",
95    "keyword.control.import",
96    "keyword.modifier",
97    "keyword.operator",
98    "label",
99    "number",
100    "operator",
101    "property",
102    "punctuation.bracket",
103    "punctuation.delimiter",
104    "punctuation.special",
105    "string",
106    "string.escape",
107    "string.regex",
108    "string.special",
109    "tag",
110    "type",
111    "type.builtin",
112    "variable",
113    "variable.builtin",
114    "variable.member",
115    "variable.parameter",
116];
117
118fn bench_build_highlight_map(c: &mut Criterion) {
119    let mut group = c.benchmark_group("build_highlight_map");
120
121    for (capture_label, capture_names) in [
122        ("small_captures", SMALL_CAPTURE_NAMES as &[&str]),
123        ("large_captures", LARGE_CAPTURE_NAMES as &[&str]),
124    ] {
125        for (theme_label, theme_keys) in [
126            ("small_theme", SMALL_THEME_KEYS as &[&str]),
127            ("large_theme", LARGE_THEME_KEYS as &[&str]),
128        ] {
129            let theme = syntax_theme(theme_keys);
130            group.bench_with_input(
131                BenchmarkId::new(capture_label, theme_label),
132                &(capture_names, &theme),
133                |b, (capture_names, theme)| {
134                    b.iter(|| build_highlight_map(black_box(capture_names), black_box(theme)));
135                },
136            );
137        }
138    }
139
140    group.finish();
141}
142
143criterion_group!(benches, bench_build_highlight_map);
144criterion_main!(benches);
145
Served at tenant.openagents/omega Member data and write actions are omitted.