Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T05:22:05.315Z 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

layout_line.rs

83 lines · 3.0 KB · rust
1use criterion::{Criterion, criterion_group, criterion_main};
2use gpui::{FontFallbacks, FontRun, PlatformTextSystem, font, px};
3use gpui_wgpu::CosmicTextSystem;
4use std::borrow::Cow;
5
6const LILEX: &[u8] = include_bytes!("../../../assets/fonts/lilex/Lilex-Regular.ttf");
7const IBM_PLEX: &[u8] =
8    include_bytes!("../../../assets/fonts/ibm-plex-sans/IBMPlexSans-Regular.ttf");
9
10// ~4 000 chars of typical ASCII code text.
11fn code_text() -> String {
12    concat!(
13        "    fn compute_run_spans(\n",
14        "        text: &str,\n",
15        "        run_offset: usize,\n",
16        "        run_len: usize,\n",
17        "        primary: FontId,\n",
18        "        fallback_chain: &[(FontId, SharedString)],\n",
19        "        covers: &impl Fn(FontId, char) -> bool,\n",
20        "    ) -> SmallVec<[RunSpan; 4]> {\n",
21        "        let mut spans = SmallVec::new();\n",
22        "        let run_end = run_offset + run_len;\n",
23        "        if run_end <= run_offset { return spans; }\n",
24        "        let run_text = &text[run_offset..run_end];\n",
25        "        let mut span_start = run_offset;\n",
26        "        let mut span_slot: Option<usize> = None;\n",
27        "        for (ch_idx, ch) in run_text.char_indices() {\n",
28        "            let abs = run_offset + ch_idx;\n",
29        "            let next = pick_covering_slot(ch, span_slot, primary, fallback_chain, covers);\n",
30        "            if next == span_slot { continue; }\n",
31        "            if abs > span_start {\n",
32        "                spans.push(RunSpan { start: span_start, end: abs, slot: span_slot });\n",
33        "            }\n",
34        "            span_start = abs;\n",
35        "            span_slot = next;\n",
36        "        }\n",
37        "        spans\n",
38        "    }\n",
39    )
40    .repeat(8) // ~3 800 chars
41}
42
43fn bench_layout_line(c: &mut Criterion) {
44    let system = CosmicTextSystem::new_without_system_fonts("Lilex");
45    system
46        .add_fonts(vec![Cow::Borrowed(LILEX), Cow::Borrowed(IBM_PLEX)])
47        .unwrap();
48
49    let font_id_no_fallback = system.font_id(&font("Lilex")).unwrap();
50
51    let font_id_with_fallback = {
52        let mut f = font("Lilex");
53        f.fallbacks = Some(FontFallbacks::from_fonts(vec!["IBM Plex Sans".to_string()]));
54        system.font_id(&f).unwrap()
55    };
56
57    let text = code_text();
58
59    let runs_no_fallback = vec![FontRun {
60        len: text.len(),
61        font_id: font_id_no_fallback,
62    }];
63    let runs_with_fallback = vec![FontRun {
64        len: text.len(),
65        font_id: font_id_with_fallback,
66    }];
67
68    let mut group = c.benchmark_group("layout_line");
69
70    group.bench_function("no_fallback", |b| {
71        b.iter(|| system.layout_line(&text, px(14.0), &runs_no_fallback))
72    });
73
74    group.bench_function("with_fallback_ascii", |b| {
75        b.iter(|| system.layout_line(&text, px(14.0), &runs_with_fallback))
76    });
77
78    group.finish();
79}
80
81criterion_group!(benches, bench_layout_line);
82criterion_main!(benches);
83
Served at tenant.openagents/omega Member data and write actions are omitted.