1use crate::ui::components::footer::Footer;
2use crate::ui::components::main_nav::{ActivePage, MainNav};
3use crate::ui::seo::{
4 breadcrumb_schema, organization_schema, pages as seo_pages, webpage_schema, BreadcrumbItem,
5 JsonLdMultiple, PageHead,
6};
7use dioxus::prelude::*;
8#[cfg(all(feature = "split", target_arch = "wasm32"))]
9use dioxus::wasm_split;
10use serde::Deserialize;
11use std::collections::HashMap;
12#[cfg(not(target_arch = "wasm32"))]
13use std::sync::LazyLock;
14#[cfg(target_arch = "wasm32")]
15use std::sync::OnceLock;
16
17fn config_from_toggles(toggles: &[bool]) -> logicaffeine_compile::optimization::OptimizationConfig {
20 let mut cfg = logicaffeine_compile::optimization::OptimizationConfig::all_off();
21 for (i, m) in logicaffeine_compile::optimization::REGISTRY
22 .iter()
23 .enumerate()
24 {
25 if toggles.get(i).copied().unwrap_or(false) {
26 cfg.set(m.opt, true);
27 }
28 }
29 cfg
30}
31
32fn toggles_from_config(cfg: &logicaffeine_compile::optimization::OptimizationConfig) -> Vec<bool> {
34 logicaffeine_compile::optimization::REGISTRY
35 .iter()
36 .map(|m| cfg.is_on(m.opt))
37 .collect()
38}
39
40mod bars;
41mod charts;
42mod codec;
43mod data;
44mod interp;
45mod jit_code;
46mod language;
47mod model;
48mod solver;
49use self::bars::*;
50use self::charts::*;
51use self::codec::*;
52use self::data::*;
53use self::interp::*;
54use self::jit_code::*;
55use self::language::*;
56use self::model::*;
57use self::solver::*;
58
59#[cfg(test)]
60#[path = "../../../../../../crates/logicaffeine_tests/unit/logicaffeine_web/ui/pages/benchmarks/tests.rs"]
61mod tests;
62
63#[cfg(test)]
64#[path = "../../../../../../crates/logicaffeine_tests/unit/logicaffeine_web/ui/pages/benchmarks/solver_data_guard.rs"]
65mod solver_data_guard;
66
67const BENCHMARKS_STYLE: &str = include_str!("style.css");
68
69#[derive(Clone, Copy, PartialEq, Eq)]
72enum BenchTab {
73 Language,
74 Solver,
75 Codec,
76}
77
78impl BenchTab {
79 fn label(self) -> &'static str {
80 match self {
81 BenchTab::Language => "Programming Language",
82 BenchTab::Solver => "SAT Solver",
83 BenchTab::Codec => "Transport Codec",
84 }
85 }
86
87 fn all() -> [BenchTab; 3] {
88 [BenchTab::Language, BenchTab::Solver, BenchTab::Codec]
89 }
90}
91
92#[derive(Clone, Copy, PartialEq, Eq, Debug)]
94enum CodeTab {
95 Rust,
96 C,
97 CBytecode,
98 Jit,
99 Vm,
100 TreeWalker,
101}
102
103impl CodeTab {
104 fn all() -> [CodeTab; 6] {
105 [
106 CodeTab::Rust,
107 CodeTab::C,
108 CodeTab::CBytecode,
109 CodeTab::Jit,
110 CodeTab::Vm,
111 CodeTab::TreeWalker,
112 ]
113 }
114
115 fn tier(self) -> &'static str {
117 match self {
118 CodeTab::Rust => "logos_release",
119 CodeTab::C => "logos_c",
120 CodeTab::CBytecode => "logos_cbc",
121 CodeTab::Jit => "logos_jit",
122 CodeTab::Vm => "logos_vm",
123 CodeTab::TreeWalker => "logos_tw",
124 }
125 }
126
127 fn fallback_label(self) -> &'static str {
128 match self {
129 CodeTab::Rust => "LOGOS (Rust)",
130 CodeTab::C => "LOGOS (C)",
131 CodeTab::CBytecode => "LOGOS (C, bytecode)",
132 CodeTab::Jit => "LOGOS (JIT)",
133 CodeTab::Vm => "LOGOS (VM)",
134 CodeTab::TreeWalker => "LOGOS (tree-walker)",
135 }
136 }
137}
138
139fn c_program_part(full: &str) -> String {
141 let sentinel = logicaffeine_compile::codegen_c::USER_CODE_SENTINEL;
142 match full.find(sentinel) {
143 Some(i) => full[i + sentinel.len()..]
144 .trim_start_matches('\n')
145 .to_string(),
146 None => full.to_string(),
147 }
148}
149
150#[component(lazy)]
155pub fn Benchmarks() -> Element {
156 #[cfg(not(target_arch = "wasm32"))]
157 return rsx! { BenchmarksLoaded {} };
158
159 #[cfg(target_arch = "wasm32")]
160 {
161 let mut bundle = use_resource(load_bench_bundle);
162 let state = bundle.read_unchecked();
163 match &*state {
164 Some(Ok(())) => rsx! { BenchmarksLoaded {} },
165 Some(Err(e)) => rsx! {
166 BenchShell {
167 p { class: "bench-gate-status error", "Benchmark data failed to load: {e}" }
168 button {
169 class: "bench-gate-retry",
170 onclick: move |_| bundle.restart(),
171 "Retry"
172 }
173 }
174 },
175 None => rsx! {
176 BenchShell {
177 p { class: "bench-gate-status", "Loading benchmark data\u{2026}" }
178 }
179 },
180 }
181 }
182}
183
184#[cfg(target_arch = "wasm32")]
187#[component]
188fn BenchShell(children: Element) -> Element {
189 rsx! {
190 PageHead {
191 title: seo_pages::BENCHMARKS.title,
192 description: seo_pages::BENCHMARKS.description,
193 canonical_path: seo_pages::BENCHMARKS.canonical_path,
194 }
195 style { "{BENCHMARKS_STYLE}" }
196 div { class: "bench-container",
197 MainNav { active: ActivePage::Benchmarks, subtitle: Some("Performance") }
198 section { class: "bench-hero",
199 h1 { "Benchmarks" }
200 {children}
201 }
202 Footer {}
203 }
204 }
205}
206
207#[component]
208fn BenchmarksLoaded() -> Element {
209 let data = bench_data().expect("gated: the Benchmarks shell loads the bundle first");
210 let display_order: Vec<usize> = {
217 let mut idx: Vec<usize> = (0..data.benchmarks.len()).collect();
218 idx.sort_by_key(|&i| data.benchmarks[i].collapse_note().is_some());
219 idx
220 };
221 let first_apples = display_order.first().copied().unwrap_or(0);
222 let mut active_bench = use_signal(move || first_apples);
223 let mut bench_tab = use_signal(|| BenchTab::Language);
224 let mut opt_toggles =
228 use_signal(|| vec![true; logicaffeine_compile::optimization::REGISTRY.len()]);
229 let mut live_rust = use_signal(|| Option::<String>::None);
234 let mut code_tab = use_signal(|| CodeTab::Rust);
237 let mut live_alt = use_signal(|| Option::<(CodeTab, Vec<bool>, String)>::None);
240 let mut alt_gen = use_signal(|| 0u64);
241 let mut chosen_size = use_signal(|| Option::<String>::None);
243 let mut compiling = use_signal(|| false);
244 let mut compile_gen = use_signal(|| 0u64);
245 let mut base_fired = use_signal(Vec::<&'static str>::new);
252 let mut fired_now = use_signal(Vec::<&'static str>::new);
253 let mut preempted_now = use_signal(Vec::<(&'static str, &'static str)>::new);
254 let mut base_preempted = use_signal(Vec::<(&'static str, &'static str)>::new);
255 let mut base_dependencies = use_signal(Vec::<(&'static str, &'static str)>::new);
256 let mut expanded =
259 use_signal(|| vec![true; logicaffeine_compile::optimization::REGISTRY.len()]);
260 let mut stats_open = use_signal(|| false);
261 let mut compile_detail_open = use_signal(|| false);
262 let mut methodology_open = use_signal(|| false);
263 let mut source_open: Signal<[bool; 10]> = use_signal(|| [false; 10]);
264
265 use_effect(move || {
276 let idx = active_bench();
277 let toggles = opt_toggles();
278 let b = &data.benchmarks[idx];
279 let kw =
280 |s: &str| logicaffeine_compile::optimization::by_keyword(s).map(|o| o.meta().keyword);
281 let baked_fired: Vec<&'static str> = b.fired.iter().filter_map(|s| kw(s)).collect();
284 let baked_blockers: Vec<(&'static str, &'static str)> = b
285 .blockers
286 .iter()
287 .filter_map(|(w, l)| Some((kw(w)?, kw(l)?)))
288 .collect();
289 let baked_deps: Vec<(&'static str, &'static str)> = b
290 .dependencies
291 .iter()
292 .filter_map(|(d, x)| Some((kw(d)?, kw(x)?)))
293 .collect();
294 base_fired.set(baked_fired.clone());
295 base_preempted.set(baked_blockers.clone());
296 base_dependencies.set(baked_deps);
297
298 let disabled: Vec<&'static str> = logicaffeine_compile::optimization::REGISTRY
299 .iter()
300 .enumerate()
301 .filter(|(i, _)| !toggles[*i])
302 .map(|(_, m)| m.keyword)
303 .collect();
304 let cache_present = !b.generated_rust.trim().is_empty();
305
306 if disabled.is_empty() {
309 fired_now.set(baked_fired);
310 preempted_now.set(baked_blockers);
311 live_rust.set(if cache_present {
312 None
313 } else {
314 Some(b.generated_rust.clone())
315 });
316 compiling.set(false);
317 return;
318 }
319
320 let decorated =
323 logicaffeine_compile::optimization::decorate_source(&b.logos_source, &disabled);
324 let gen = *compile_gen.peek() + 1;
325 compile_gen.set(gen);
326 compiling.set(true);
327 spawn(async move {
328 gloo_timers::future::TimeoutFuture::new(30).await;
329 if *compile_gen.peek() != gen {
330 return;
331 }
332 let (rust, fired, preempted) = logicaffeine_compile::compile::compile_to_rust_traced(
333 &decorated,
334 )
335 .unwrap_or_else(|e| (format!("// compile error: {e:?}"), Vec::new(), Vec::new()));
336 if *compile_gen.peek() != gen {
337 return;
338 }
339 fired_now.set(fired);
340 preempted_now.set(preempted);
341 live_rust.set(Some(rust));
342 compiling.set(false);
343 });
344 });
345
346 #[cfg(target_arch = "wasm32")]
348 let jit_loaded = use_resource(move || async move {
349 if code_tab() == CodeTab::Jit {
350 load_jit_code().await;
351 }
352 code_tab()
353 });
354 #[cfg(target_arch = "wasm32")]
355 let _ = jit_loaded.read();
356
357 use_effect(move || {
360 let tab = code_tab();
361 let toggles = opt_toggles();
362 let idx = active_bench();
363 if !matches!(tab, CodeTab::C | CodeTab::Vm) {
364 return;
365 }
366 if tab == CodeTab::C && toggles.iter().all(|on| *on) {
367 return;
368 }
369 let disabled: Vec<&'static str> = logicaffeine_compile::optimization::REGISTRY
370 .iter()
371 .enumerate()
372 .filter(|(i, _)| !toggles[*i])
373 .map(|(_, m)| m.keyword)
374 .collect();
375 let decorated = logicaffeine_compile::optimization::decorate_source(
376 &data.benchmarks[idx].logos_source,
377 &disabled,
378 );
379 let gen = *alt_gen.peek() + 1;
380 alt_gen.set(gen);
381 spawn(async move {
382 gloo_timers::future::TimeoutFuture::new(30).await;
383 if *alt_gen.peek() != gen {
384 return;
385 }
386 let text = match tab {
387 CodeTab::C => logicaffeine_compile::compile::compile_to_c(&decorated)
388 .map(|c| c_program_part(&c))
389 .unwrap_or_else(|e| format!("// the C generator refused this program: {e:?}")),
390 _ => logicaffeine_compile::ui_bridge::vm_listing(&decorated)
391 .unwrap_or_else(|why| format!("; {why}")),
392 };
393 if *alt_gen.peek() != gen {
394 return;
395 }
396 live_alt.set(Some((tab, toggles, text)));
397 });
398 });
399
400 let breadcrumbs = vec![
401 BreadcrumbItem {
402 name: "Home",
403 path: "/",
404 },
405 BreadcrumbItem {
406 name: "Benchmarks",
407 path: "/benchmarks",
408 },
409 ];
410 let schemas = vec![
411 organization_schema(),
412 webpage_schema(
413 "LOGOS Benchmarks",
414 seo_pages::BENCHMARKS.description,
415 "/benchmarks",
416 ),
417 breadcrumb_schema(&breadcrumbs),
418 ];
419
420 let interp = interp_data().expect("gated: the Benchmarks shell loads the bundle first");
421 let collapsed: std::collections::HashSet<&str> = data
423 .benchmarks
424 .iter()
425 .filter(|b| b.collapse_note().is_some())
426 .map(|b| b.id.as_str())
427 .collect();
428 let interp_speed = interp_speed_vs_v8(interp, &collapsed);
429 let aot_speed = aot_speed_vs_v8(interp);
430 let collapse_count = data
431 .benchmarks
432 .iter()
433 .filter(|b| b.collapse_note().is_some())
434 .count();
435
436 let bench = &data.benchmarks[active_bench()];
437 let bench_sources = bench_sources_for(&bench.id)
438 .expect("sources_cover_every_benchmark locks every benchmark id to a sources entry");
439
440 let opt_tog = opt_toggles();
447 let opt_disabled: Vec<&'static str> = logicaffeine_compile::optimization::REGISTRY
448 .iter()
449 .enumerate()
450 .filter(|(i, _)| !opt_tog[*i])
451 .map(|(_, m)| m.keyword)
452 .collect();
453 let opt_decorated =
454 logicaffeine_compile::optimization::decorate_source(&bench.logos_source, &opt_disabled);
455 let all_opts_on = opt_disabled.is_empty();
456
457 let opt_tree: Vec<logicaffeine_compile::optimization::OptNode> = {
466 use logicaffeine_compile::optimization::by_keyword;
467 let fired: Vec<_> = base_fired()
468 .iter()
469 .filter_map(|kw| by_keyword(kw))
470 .collect();
471 let preempted: Vec<_> = base_preempted()
472 .iter()
473 .filter_map(|(w, l)| Some((by_keyword(w)?, by_keyword(l)?)))
474 .collect();
475 let dependencies: Vec<_> = base_dependencies()
476 .iter()
477 .filter_map(|(d, x)| Some((by_keyword(d)?, by_keyword(x)?)))
478 .collect();
479 logicaffeine_compile::optimization::relationship_tree(&fired, &preempted, &dependencies)
480 };
481
482 let tree_visible: Vec<bool> = {
486 let exp = expanded();
487 let mut vis = Vec::with_capacity(opt_tree.len());
488 let mut hide_from: Option<usize> = None;
489 for node in &opt_tree {
490 if let Some(d) = hide_from {
491 if node.depth <= d {
492 hide_from = None;
493 }
494 }
495 let visible = hide_from.is_none();
496 if visible && node.has_children && !exp.get(node.opt as usize).copied().unwrap_or(true)
497 {
498 hide_from = Some(node.depth);
499 }
500 vis.push(visible);
501 }
502 vis
503 };
504
505 let cache_ok = !bench.generated_rust.trim().is_empty();
506 let rust_loading = (!all_opts_on || !cache_ok) && (compiling() || live_rust().is_none());
507 let rust_text: String = if all_opts_on && cache_ok {
508 bench.generated_rust.clone()
509 } else {
510 live_rust().unwrap_or_default()
511 };
512 let code_tabs: Vec<(CodeTab, String)> = CodeTab::all()
514 .into_iter()
515 .map(|t| {
516 let label = data
517 .languages
518 .iter()
519 .find(|l| l.id == t.tier())
520 .map(|l| l.label.clone());
521 (t, label.unwrap_or_else(|| t.fallback_label().to_string()))
522 })
523 .collect();
524 let tab = code_tab();
525 let stage_trace = match tab {
526 CodeTab::Rust => &bench.optimization_stages.compiled,
527 CodeTab::C => &bench.optimization_stages.c,
528 CodeTab::CBytecode => &bench.optimization_stages.c_bytecode,
529 CodeTab::Jit => &bench.optimization_stages.jit,
530 CodeTab::Vm => &bench.optimization_stages.vm,
531 CodeTab::TreeWalker => &bench.optimization_stages.run,
532 };
533 let optimizer_trace = stage_trace.optimizer.join(", ");
534 let lowering_trace = stage_trace.lowering.join(", ");
535 let decline_trace = stage_trace.declines.join("; ");
536 let fallback_trace = stage_trace.fallbacks.join("; ");
537 let native_jit_trace = if tab == CodeTab::Jit {
538 bench
539 .jit
540 .as_ref()
541 .map(|jit| jit.optimizations.join(", "))
542 .unwrap_or_default()
543 } else {
544 String::new()
545 };
546 let (native_jit_compiled, native_jit_declines, native_jit_execution) = if tab == CodeTab::Jit {
547 bench
548 .jit
549 .as_ref()
550 .map(|jit| {
551 (
552 jit.compiled.clone().unwrap_or_default(),
553 jit.declines.clone(),
554 jit.execution.clone(),
555 )
556 })
557 .unwrap_or_default()
558 } else {
559 (String::new(), String::new(), String::new())
560 };
561 let alt_text: Option<String> = live_alt()
562 .filter(|(t, toggles, _)| *t == tab && *toggles == opt_tog)
563 .map(|(_, _, text)| text);
564 let loading = rsx! {
565 div { class: "bench-source-code", span { class: "bench-compiling", "Compiling\u{2026}" } }
566 };
567 let as_measured = if all_opts_on {
568 ", every optimization on"
569 } else {
570 ", with the optimizations above switched off"
571 };
572 let code_body: Element = match tab {
573 CodeTab::Rust if rust_loading => loading,
574 CodeTab::Rust => rsx! {
575 div { class: "bench-source-note",
576 "The Rust " code { "largo build --release" } " hands to cargo{as_measured}."
577 }
578 div { class: "bench-source-code", "{rust_text}" }
579 },
580 CodeTab::C => {
581 let text = if all_opts_on {
582 Some(bench.generated_c.clone()).filter(|c| !c.trim().is_empty())
583 } else {
584 alt_text
585 };
586 match text {
587 Some(text) => rsx! {
588 div { class: "bench-source-note",
589 "The C " code { "largo build --release --emit c" } " generates from the program{as_measured}. "
590 "The runtime it links against is the same for every benchmark and is not shown."
591 }
592 div { class: "bench-source-code", "{text}" }
593 },
594 None if all_opts_on => {
595 rsx! { div { class: "bench-source-code", "This run did not emit C for this benchmark." } }
596 }
597 None => loading,
598 }
599 }
600 CodeTab::CBytecode if bench.generated_c_bytecode.trim().is_empty() => rsx! {
601 div { class: "bench-source-code", "This run did not emit C from the bytecode for this benchmark." }
602 },
603 CodeTab::CBytecode => rsx! {
604 div { class: "bench-source-note",
605 "The C " code { "largo build --release --emit c-bytecode" } " generates from the program's bytecode, "
606 "every optimization on: the build the run measured"
607 {if all_opts_on { "." } else { " (the browser does not rebuild this form, so the toggles above do not change it)." }}
608 }
609 div { class: "bench-source-code", "{bench.generated_c_bytecode}" }
610 },
611 CodeTab::Jit => match jit_code_data()
612 .and_then(|d| d.benchmarks.get(&bench.id))
613 .filter(|r| !r.is_empty())
614 {
615 Some(regions) => rsx! {
616 div { class: "bench-source-note",
617 "The x86-64 machine code the JIT emitted while the run verified this benchmark, every optimization "
618 "on: each function and loop that got hot, disassembled at the address it ran from."
619 }
620 div { class: "bench-source-code bench-asm",
621 for region in regions.iter() {
622 div { class: "bench-asm-region", key: "{region.start}",
623 div { class: "bench-asm-title", "{region.title()} \u{00b7} {region.bytes} bytes at {region.start}" }
624 "{region.asm}"
625 }
626 }
627 }
628 },
629 None if !jit_code_settled() => loading,
630 None => rsx! {
631 div { class: "bench-source-code",
632 "This run recorded no machine code for this benchmark: nothing in it got hot enough to compile, or the "
633 "run was assembled without the JIT's code."
634 }
635 },
636 },
637 CodeTab::Vm => match alt_text {
638 Some(text) => rsx! {
639 div { class: "bench-source-note",
640 "The bytecode " code { "largo run --interpret --engine vm" } " runs, one section per function, "
641 "built in your browser{as_measured}."
642 }
643 div { class: "bench-source-code", "{text}" }
644 },
645 None => loading,
646 },
647 CodeTab::TreeWalker => rsx! {
648 div { class: "bench-source-note",
649 code { "largo run --interpret --engine tree" } " interprets the optimized syntax tree directly; there is "
650 "no compiled form. The program it parses:"
651 }
652 div { class: "bench-source-code", "{opt_decorated}" }
653 },
654 };
655
656 let ref_size = if bench.scaling.contains_key(bench.reference_size.as_str()) {
658 bench.reference_size.clone()
659 } else {
660 bench
661 .sizes
662 .last()
663 .cloned()
664 .unwrap_or_else(|| bench.reference_size.clone())
665 };
666 let mut timed_sizes: Vec<String> = bench.scaling.keys().cloned().collect();
669 timed_sizes.sort_by_key(|n| n.parse::<u64>().unwrap_or(u64::MAX));
670 let shown_size = chosen_size()
671 .filter(|n| bench.scaling.contains_key(n.as_str()))
672 .unwrap_or_else(|| ref_size.clone());
673 let ref_timings = bench.scaling.get(shown_size.as_str());
674
675 let mut stats_entries: Vec<(&str, &str, Option<&TimingResult>)> = Vec::new();
677 let ref_timed_out = bench.timed_out.get(shown_size.as_str());
678 if let Some(timings) = ref_timings {
679 for lang in &data.languages {
680 if let Some(t) = timings.get(&lang.id) {
681 stats_entries.push((&lang.label, &lang.id, Some(t)));
682 } else if ref_timed_out.is_some_and(|m| m.contains_key(&lang.id)) {
683 stats_entries.push((&lang.label, &lang.id, None));
684 }
685 }
686 }
687 stats_entries.sort_by(|a, b| match (a.2, b.2) {
688 (Some(ta), Some(tb)) => ta
689 .median_ms
690 .partial_cmp(&tb.median_ms)
691 .unwrap_or(std::cmp::Ordering::Equal),
692 (Some(_), None) => std::cmp::Ordering::Less,
693 (None, Some(_)) => std::cmp::Ordering::Greater,
694 (None, None) => std::cmp::Ordering::Equal,
695 });
696
697 let mut compile_entries: Vec<(&str, f64, f64, bool)> = bench
699 .compilation
700 .iter()
701 .map(|(name, r)| {
702 (
703 name.as_str(),
704 r.mean_ms,
705 r.stddev_ms,
706 name.starts_with("logos"),
707 )
708 })
709 .collect();
710 compile_entries.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap_or(std::cmp::Ordering::Equal));
711
712 let compile_max = compile_entries.last().map(|e| e.1).unwrap_or(1.0);
713
714 let interp_bench = interp.benchmarks.iter().find(|ib| ib.id == bench.id);
716 let mut interp_bars: Vec<(&'static str, &'static str, f64, bool, bool)> = Vec::new();
718 let mut interp_n = String::new();
719 let mut interp_engine = String::new();
720 let mut interp_active_speed: Option<f64> = None;
721 if let Some(ib) = interp_bench {
722 interp_n = ib.reference_size.clone();
723 interp_engine = ib.interpreter_engine.clone();
724 if let Some(t) = interp_ref(ib) {
725 for id in ["logos_interp", "logos_tiered", "logos_aot", "js"] {
729 if let Some(tr) = t.get(id) {
730 let lbl = if id == "js" {
731 "Node / V8"
732 } else {
733 lang_label(id)
734 };
735 let col = bar_class(id);
736 let is_logos = id.starts_with("logos");
737 interp_bars.push((
738 lbl,
739 col,
740 tr.median_ms,
741 is_logos,
742 id == "js" && node_floored(tr),
743 ));
744 }
745 }
746 if let (Some(j), Some(l)) = (t.get("js"), t.get("logos_interp")) {
747 if l.median_ms > 0.0 {
748 interp_active_speed = Some(j.median_ms / l.median_ms);
749 }
750 }
751 }
752 }
753 interp_bars.sort_by(|a, b| a.2.partial_cmp(&b.2).unwrap_or(std::cmp::Ordering::Equal));
754 let interp_max = interp_bars
755 .iter()
756 .map(|e| e.2)
757 .fold(0.0_f64, f64::max)
758 .max(1e-9);
759 if interp_engine.is_empty() {
760 interp_engine = "\u{2014}".to_string();
761 }
762 let interp_offfloor = interp
763 .benchmarks
764 .iter()
765 .filter(|ib| interp_counts(ib, &collapsed))
766 .count();
767 let interp_node_ver = if interp.metadata.node.is_empty() {
768 "Node".to_string()
769 } else {
770 format!("Node {}", interp.metadata.node)
771 };
772
773 let mut startup_bars: Vec<(&'static str, &'static str, f64, bool)> = Vec::new();
776 for id in ["logos_interp", "js"] {
777 if let Some(t) = interp.startup.engines.get(id) {
778 if t.mean_ms > 0.0 {
779 let lbl = match id {
780 "logos_interp" => "LOGOS interp",
781 "js" => "Node / V8",
782 _ => id,
783 };
784 let col = bar_class(id);
785 startup_bars.push((lbl, col, t.mean_ms, id == "logos_interp"));
786 }
787 }
788 }
789 startup_bars.sort_by(|a, b| a.2.partial_cmp(&b.2).unwrap_or(std::cmp::Ordering::Equal));
790 let startup_max = startup_bars
791 .iter()
792 .map(|e| e.2)
793 .fold(0.0_f64, f64::max)
794 .max(1e-9);
795 let startup_logos = interp
796 .startup
797 .engines
798 .get("logos_interp")
799 .map(|t| t.mean_ms)
800 .unwrap_or(0.0);
801 let startup_node = interp
802 .startup
803 .engines
804 .get("js")
805 .map(|t| t.mean_ms)
806 .unwrap_or(0.0);
807 let startup_vs_v8 = if startup_logos > 0.0 {
808 startup_node / startup_logos
809 } else {
810 0.0
811 };
812
813 let mut engine_size_bars: Vec<(&'static str, &'static str, f64, Option<f64>, bool)> =
815 Vec::new();
816 let mut wasm_bundle_bytes = 0.0_f64;
817 if let Some(es) = &interp.interpreter_sizes {
818 for id in ["logos", "node", "deno", "bun"] {
819 if let Some(s) = es.engines.get(id) {
820 if s.as_built > 0.0 {
821 let lbl = match id {
822 "logos" => "largo (LOGOS VM+JIT)",
823 "node" => "Node / V8",
824 "deno" => "Deno",
825 "bun" => "Bun",
826 _ => id,
827 };
828 let col = if id == "logos" {
829 bar_class("logos_jit")
830 } else {
831 bar_class(id)
832 };
833 engine_size_bars.push((lbl, col, s.as_built, s.stripped, id == "logos"));
834 }
835 }
836 }
837 wasm_bundle_bytes = es.wasm_bundle_bytes.unwrap_or(0.0);
838 }
839 engine_size_bars.sort_by(|a, b| a.2.partial_cmp(&b.2).unwrap_or(std::cmp::Ordering::Equal));
840 let engine_size_max = engine_size_bars
841 .iter()
842 .map(|e| e.2)
843 .fold(0.0_f64, f64::max)
844 .max(1.0);
845 let wasm_bundle_str = if wasm_bundle_bytes > 0.0 {
846 format_bytes(wasm_bundle_bytes)
847 } else {
848 String::new()
849 };
850
851 let source_langs = [
853 "c", "cpp", "rust", "zig", "go", "java", "js", "python", "ruby", "nim",
854 ];
855
856 let commit_url = format!("{}/commit/{}", GITHUB_REPO, data.metadata.commit);
857 let release_url = format!(
858 "{}/releases/tag/v{}",
859 GITHUB_REPO, data.metadata.logos_version
860 );
861 let raw_json_url = format!("{}/blob/main/benchmarks/results/latest.json", GITHUB_REPO);
862 let solver_meta = &solver_data()
864 .expect("gated: the Benchmarks shell loads the bundle first")
865 .metadata;
866 let codec_meta = &codec_data()
867 .expect("gated: the Benchmarks shell loads the bundle first")
868 .metadata;
869 let solver_json_url = format!("{}/blob/main/benchmarks/results/solvers.json", GITHUB_REPO);
870 let codec_json_url = format!(
871 "{}/blob/main/benchmarks/results/latest-codec.json",
872 GITHUB_REPO
873 );
874 let solver_date = solver_meta
875 .date
876 .get(..10)
877 .unwrap_or(solver_meta.date.as_str());
878 let codec_date = codec_meta
879 .date
880 .get(..10)
881 .unwrap_or(codec_meta.date.as_str());
882 let history_url = format!("{}/tree/main/benchmarks/results/history", GITHUB_REPO);
883 let runsh_url = format!("{}/blob/main/benchmarks/run.sh", GITHUB_REPO);
884 let bench_dir_url = format!("{}/tree/main/benchmarks", GITHUB_REPO);
885
886 rsx! {
887 PageHead {
888 title: seo_pages::BENCHMARKS.title,
889 description: seo_pages::BENCHMARKS.description,
890 canonical_path: seo_pages::BENCHMARKS.canonical_path,
891 }
892 style { "{BENCHMARKS_STYLE}" }
893 JsonLdMultiple { schemas }
894
895 div { class: "bench-container",
896 MainNav { active: ActivePage::Benchmarks, subtitle: Some("Performance") }
897
898 section { class: "bench-hero", id: "overview",
900 h1 { "Benchmarks" }
901 if bench_tab() == BenchTab::Language {
902 p {
903 "LOGOS runs six ways: compiled through Rust, compiled to C from the program and from its "
904 "bytecode, on our x86-64 JIT, on the bytecode VM, and on the tree-walking interpreter. Here is "
905 "each one against the languages people pick when speed matters, from programs with "
906 "English-level readability."
907 }
908 div { class: "bench-pills",
909 a { class: "bench-pill", href: "{release_url}", target: "_blank",
910 strong { "v{data.metadata.logos_version}" }
911 }
912 a { class: "bench-pill", href: "{commit_url}", target: "_blank",
913 "{data.metadata.commit}"
914 }
915 span { class: "bench-pill", "{data.metadata.cpu}" }
916 span { class: "bench-pill", "{data.metadata.os}" }
917 span { class: "bench-pill", "{data.metadata.day()}" }
918 if let Some(env) = &data.metadata.environment {
919 if !env.pinning.cpus.is_empty() {
920 span { class: "bench-pill", title: "Every timed command ran on these CPUs ({env.pinning.source}).",
921 "Pinned to CPUs {env.pinning.cpus}"
922 }
923 }
924 if env.noisy() {
925 span { class: "bench-pill warn",
926 title: "This run skipped the quiet-machine check, so another workload may have shared the CPUs.",
927 "Noisy run"
928 }
929 }
930 }
931 a { class: "bench-pill link", href: "{raw_json_url}", target: "_blank",
932 "Raw JSON"
933 }
934 a { class: "bench-pill link", href: "/data/flamegraphs.pdf",
935 download: "logos-flamegraphs.pdf",
936 "\u{2b07} Flamegraph PDF"
937 }
938 }
939 }
940 if bench_tab() == BenchTab::Solver {
941 p { "Certified proofs in milliseconds \u{2014} the same pure-Rust prover that runs in your browser, with no Z3." }
942 div { class: "bench-pills",
943 if !solver_meta.cpu.is_empty() {
944 span { class: "bench-pill", "{solver_meta.cpu}" }
945 }
946 if !solver_meta.kissat.is_empty() {
947 span { class: "bench-pill", "Kissat {solver_meta.kissat}" }
948 }
949 if !solver_meta.date.is_empty() {
950 span { class: "bench-pill", "{solver_date}" }
951 }
952 a { class: "bench-pill link", href: "{solver_json_url}", target: "_blank",
953 "Raw JSON"
954 }
955 }
956 }
957 if bench_tab() == BenchTab::Codec {
958 p { "Smallest bytes on the wire \u{2014} the LOGOS codec, head-to-head against the industry serializers." }
959 div { class: "bench-pills",
960 if !codec_meta.cpu.is_empty() {
961 span { class: "bench-pill", "{codec_meta.cpu}" }
962 }
963 if !codec_meta.os.is_empty() {
964 span { class: "bench-pill", "{codec_meta.os}" }
965 }
966 if !codec_meta.date.is_empty() {
967 span { class: "bench-pill", "{codec_date}" }
968 }
969 a { class: "bench-pill link", href: "{codec_json_url}", target: "_blank",
970 "Raw JSON"
971 }
972 }
973 }
974 }
975
976 nav { class: "bench-tabbar",
978 for t in BenchTab::all() {
979 button {
980 key: "{t.label()}",
981 class: if bench_tab() == t { "bench-tabbar-btn active" } else { "bench-tabbar-btn" },
982 onclick: move |_| bench_tab.set(t),
983 "{t.label()}"
984 }
985 }
986 }
987
988 if bench_tab() == BenchTab::Language {
990 nav { class: "bench-section-nav",
991 a { href: "#overview", "Overview" }
992 a { href: "#performance", "Performance" }
993 a { href: "#interpreter", "Interpreter" }
994 a { href: "#source", "Source Code" }
995 a { href: "#compilation", "Compilation" }
996 a { href: "#summary", "Summary" }
997 a { href: "#methodology", "Methodology" }
998 }
999 }
1000
1001 if bench_tab() == BenchTab::Language {
1002 div { class: "bench-content",
1003 div { class: "bench-summary bench-summary-tiers",
1006 for card in tier_headlines(data).iter() {
1007 div { class: "bench-summary-card bench-summary-{card.id}",
1008 div { class: "bench-summary-eyebrow", "{card.label}" }
1009 div { class: "bench-summary-value",
1010 {card.vs_c.map(|v| format!("{v:.2}×")).unwrap_or_else(|| "—".to_string())}
1011 }
1012 div { class: "bench-summary-label", "the speed of C, geometric mean" }
1013 if let Some(same) = card.same_algorithm {
1014 div { class: "bench-summary-sub", "{same:.2}× where every language runs the same algorithm" }
1015 }
1016 if let Some((k, n)) = card.coverage {
1017 div { class: "bench-summary-sub", "{k} of {n} benchmarks" }
1018 }
1019 }
1020 }
1021 }
1022
1023 div { class: "bench-intro",
1024 p {
1025 "Benchmarks are easy to rig, so we've tried to make ours easy to check. Every program on this "
1026 "page computes the same answer in every language, byte for byte, at every size we time, and "
1027 "every number comes out of one script you can run on your own machine. LOGOS shows up once for "
1028 "every way it runs: compiled through Rust, compiled to C from the program and from its "
1029 "bytecode, on our x86-64 JIT, on the bytecode VM alone, and on the tree-walking interpreter. "
1030 "Each one's output is in the panel under the source, so you can read what actually ran."
1031 }
1032 p {
1033 "Sometimes the compiler wins by doing less work, like folding a recursion into a closed form. "
1034 "Those benchmarks are marked \u{26a1}, the second number on each card leaves them out, and the "
1035 "generated code is right there to read. A faster algorithm and faster machine code are two "
1036 "different claims, and we'd rather you didn't have to take our word for either."
1037 }
1038 }
1039
1040 div { class: "bench-tabs",
1042 for &i in display_order.iter() {
1043 button {
1044 key: "{i}",
1045 class: if active_bench() == i { "bench-tab active" } else { "bench-tab" },
1046 onclick: move |_| {
1047 active_bench.set(i);
1048 stats_open.set(false);
1049 compile_detail_open.set(false);
1050 source_open.set([false; 10]);
1051 opt_toggles.set(vec![true; logicaffeine_compile::optimization::REGISTRY.len()]);
1054 live_rust.set(None);
1055 live_alt.set(None);
1056 chosen_size.set(None);
1057 compiling.set(false);
1058 base_fired.set(Vec::new());
1059 fired_now.set(Vec::new());
1060 preempted_now.set(Vec::new());
1061 base_preempted.set(Vec::new());
1062 base_dependencies.set(Vec::new());
1063 expanded.set(vec![true; logicaffeine_compile::optimization::REGISTRY.len()]);
1064 },
1065 "{data.benchmarks[i].name}"
1066 if data.benchmarks[i].collapse_note().is_some() {
1067 span { class: "bench-tab-badge", title: "Algorithm collapsed by the LOGOS compiler", "\u{26a1}" }
1068 }
1069 }
1070 }
1071 }
1072
1073 div { class: "bench-section", id: "performance",
1075 div { class: "bench-section-title", "{bench.name}" }
1076 div { class: "bench-section-desc",
1077 "{bench.description} (n = {shown_size})"
1078 }
1079
1080 if let Some(note) = bench.collapse_note() {
1081 div { class: "bench-callout",
1082 span { class: "bench-callout-icon", "\u{26a1}" }
1083 span { "{note}" }
1084 }
1085 }
1086
1087 if timed_sizes.len() > 1 {
1088 div { class: "bench-size-pills", role: "tablist", "aria-label": "Problem size",
1089 for n in timed_sizes.iter().cloned() {
1090 button {
1091 key: "{n}",
1092 class: if n == shown_size { "bench-size-pill active" } else { "bench-size-pill" },
1093 role: "tab",
1094 "aria-selected": "{n == shown_size}",
1095 onclick: {
1096 let n = n.clone();
1097 move |_| chosen_size.set(Some(n.clone()))
1098 },
1099 "n = {n}"
1100 if n == ref_size {
1101 span { class: "bench-size-ref", " reference" }
1102 }
1103 }
1104 }
1105 }
1106 }
1107 div { class: "bench-chart-hint", "Wall-clock time at n = {shown_size} \u{2014} shorter bar is faster." }
1108
1109 BarChart {
1110 groups: chart_groups(
1111 &data.languages,
1112 ref_timings,
1113 bench.timed_out.get(shown_size.as_str()),
1114 bench.limits.get(shown_size.as_str()),
1115 ),
1116 unit: BarUnit::Millis,
1117 }
1118
1119 div {
1121 class: "bench-section-desc bench-subhead",
1122 "Scaling \u{2014} time vs problem size (log\u{2013}log)"
1123 }
1124 {scaling_chart(bench, &data.languages)}
1125
1126 {complexity_panel(bench, &data.languages)}
1127
1128 if bench.memory.is_some() {
1130 div {
1131 class: "bench-section-desc bench-subhead",
1132 "Memory \u{2014} peak resident set size"
1133 }
1134 {memory_bar_chart(bench, &data.languages)}
1135 }
1136
1137 if bench.binary_sizes.is_some() {
1139 div {
1140 class: "bench-section-desc bench-subhead",
1141 "Binary size \u{2014} compiled-artifact footprint"
1142 }
1143 {binary_size_bar_chart(bench, &data.languages)}
1144 div { class: "bench-note", style: "margin-top:12px;",
1145 "The size of the program you actually ship. C and C++ stay tiny because the runtime lives in the system libc; Rust and Go statically link their runtimes; LOGOS compiles to a compact self-contained binary in between. "
1146 "Java\u{2019}s figure is its bytecode alone \u{2014} it still needs the JVM to run \u{2014} and JavaScript has no compiled artifact at all (its footprint is the V8 engine, in the Interpreter section). "
1147 "As-built is the real shipped file; stripped removes debug symbols for a code-only comparison."
1148 }
1149 }
1150
1151 button {
1153 class: "bench-collapsible-btn",
1154 onclick: move |_| stats_open.set(!stats_open()),
1155 span {
1156 class: if stats_open() { "bench-collapsible-chevron open" } else { "bench-collapsible-chevron" },
1157 "\u{25b6}"
1158 }
1159 "Detailed Statistics"
1160 }
1161 div {
1162 class: if stats_open() { "bench-collapsible-body open" } else { "bench-collapsible-body" },
1163 table { class: "bench-stats-table",
1164 thead {
1165 tr {
1166 th { "Language" }
1167 th { "Mean" }
1168 th { "Median" }
1169 th { "StdDev" }
1170 th { "Min" }
1171 th { "Max" }
1172 th { "User" }
1173 th { "System" }
1174 th { "CV" }
1175 th { "Runs" }
1176 }
1177 }
1178 tbody {
1179 for (label, lid, maybe_t) in stats_entries.iter() {
1180 if let Some(t) = maybe_t {
1181 tr {
1182 class: if lid.starts_with("logos_") { "highlight" } else { "" },
1183 td { "{label}" }
1184 td { "{format_time(t.mean_ms)}" }
1185 td { "{format_time(t.median_ms)}" }
1186 td { "\u{00b1}{format_time(t.stddev_ms)}" }
1187 td { "{format_time(t.min_ms)}" }
1188 td { "{format_time(t.max_ms)}" }
1189 td { "{t.user_ms.map(|v| format_time(v)).unwrap_or_else(|| \"\u{2014}\".to_string())}" }
1190 td { "{t.system_ms.map(|v| format_time(v)).unwrap_or_else(|| \"\u{2014}\".to_string())}" }
1191 td { "{t.cv:.3}" }
1192 td { "{t.runs}" }
1193 }
1194 } else {
1195 {
1196 let timeout_str = ref_timed_out
1197 .and_then(|m| m.get(*lid))
1198 .map(|t| format_timeout(*t))
1199 .unwrap_or_else(|| ">timeout".to_string());
1200 rsx! {
1201 tr {
1202 class: if lid.starts_with("logos_") { "highlight" } else { "" },
1203 td { "{label}" }
1204 td { "{timeout_str}" }
1205 td { "{timeout_str}" }
1206 td { "\u{2014}" }
1207 td { "\u{2014}" }
1208 td { "\u{2014}" }
1209 td { "\u{2014}" }
1210 td { "\u{2014}" }
1211 td { "\u{2014}" }
1212 td { "\u{2014}" }
1213 }
1214 }
1215 }
1216 }
1217 }
1218 }
1219 }
1220 }
1221 }
1222
1223 div { class: "bench-section", id: "interpreter",
1225 div { class: "bench-section-title", "LOGOS vs JavaScript / V8" }
1226 div { class: "bench-section-desc",
1227 "The LOGOS engine ladder \u{2014} bytecode VM, copy-and-patch JIT, and the warm AOT-native tier \u{2014} against {interp_node_ver} / V8."
1228 }
1229
1230 div { class: "bench-summary", style: "margin-bottom: 20px;",
1231 div { class: "bench-summary-card",
1232 div { class: "bench-summary-value cyan", "{startup_vs_v8:.1}x" }
1233 div { class: "bench-summary-label", "faster cold start than V8" }
1234 }
1235 div { class: "bench-summary-card",
1236 div { class: "bench-summary-value cyan", "{startup_logos:.1}ms" }
1237 div { class: "bench-summary-label", "LOGOS interpreter cold start" }
1238 }
1239 div { class: "bench-summary-card",
1240 div { class: "bench-summary-value purple", "{interp_speed:.2}x" }
1241 div { class: "bench-summary-label", "the speed of V8 on compute (geomean)" }
1242 }
1243 if aot_speed > 0.0 {
1244 div { class: "bench-summary-card",
1245 div { class: "bench-summary-value cyan", "{aot_speed:.2}x" }
1246 div { class: "bench-summary-label", "the speed of V8, AOT-native warm (geomean)" }
1247 }
1248 }
1249 }
1250
1251 if !startup_bars.is_empty() {
1253 div { class: "bench-chart-hint bench-chart-hint-strong", style: "margin-top: 4px;",
1254 "Cold start \u{2014} launch the engine and run a trivial program ({interp.startup.runs} runs, shorter is faster)"
1255 }
1256 div { class: "bench-chart",
1257 for (label, bar_class, mean, _is_logos) in startup_bars.iter() {
1258 {
1259 let pct = (*mean / startup_max * 100.0).min(100.0);
1260 let time_str = format_time(*mean);
1261 let show_inside = pct > 18.0;
1262 rsx! {
1263 div { class: "bench-bar-row",
1264 div { class: "bench-bar-label", "{label}" }
1265 div { class: "bench-bar-track",
1266 div { class: "{bar_class}", style: "width: {pct:.1}%;",
1267 if show_inside { span { class: "bench-bar-time", "{time_str}" } }
1268 }
1269 }
1270 if !show_inside { span { class: "bench-bar-time-outside", "{time_str}" } }
1271 }
1272 }
1273 }
1274 }
1275 }
1276 div { class: "bench-note", style: "margin-top:14px;margin-bottom:0;",
1277 "A native binary has no VM to warm up, so the LOGOS interpreter reaches first output in "
1278 strong { "{startup_logos:.1}ms" }
1279 " versus V8\u{2019}s {startup_node:.0}ms, about "
1280 strong { "{startup_vs_v8:.1}x quicker" }
1281 ", which is what matters for short-lived work like cloud functions, CLI tools, and scripts. "
1282 "On long-running loops V8\u{2019}s optimizing JIT pulls ahead: the interpreter is competitive on "
1283 "memory-bound work and behind on heavy compute, a geometric mean of {interp_speed:.2}x the "
1284 "speed of V8 across {interp_offfloor} benchmarks."
1285 }
1286 }
1287
1288 if !engine_size_bars.is_empty() {
1290 div { class: "bench-chart-hint bench-chart-hint-strong", style: "margin-top: 22px;",
1291 "Engine size \u{2014} the runtime you ship to execute a program (shorter ships less; stripped, code-only size in parentheses)"
1292 }
1293 div { class: "bench-chart",
1294 for (label, bar_class, bytes, stripped, _is_logos) in engine_size_bars.iter() {
1295 {
1296 let pct = (*bytes / engine_size_max * 100.0).min(100.0);
1297 let s = footprint_label(*bytes, *stripped);
1298 let show_inside = pct > 32.0;
1299 rsx! {
1300 div { class: "bench-bar-row",
1301 div { class: "bench-bar-label", "{label}" }
1302 div { class: "bench-bar-track",
1303 div { class: "{bar_class}", style: "width: {pct:.1}%;",
1304 if show_inside { span { class: "bench-bar-time", "{s}" } }
1305 }
1306 }
1307 if !show_inside { span { class: "bench-bar-time-outside", "{s}" } }
1308 }
1309 }
1310 }
1311 }
1312 }
1313 div { class: "bench-note", style: "margin-top:14px;",
1314 if !wasm_bundle_str.is_empty() {
1315 "In the browser the whole LOGOS engine ships as a "
1316 strong { "{wasm_bundle_str}" }
1317 " WebAssembly bundle \u{2014} the same VM+JIT, no native install. "
1318 }
1319 "Node\u{2019}s binary bundles V8, libuv, and ICU; largo bundles the transpiler, bytecode VM, and copy-and-patch JIT \u{2014} each is the whole engine you ship to run a program. As-built is the real file; stripped removes debug symbols."
1320 }
1321 }
1322
1323 div { class: "bench-chart-hint bench-chart-hint-strong", style: "margin-top: 22px;",
1324 "{bench.name} (engine: {interp_engine})"
1325 }
1326
1327 if bench.id == "ackermann" {
1328 div { class: "bench-callout",
1329 span { class: "bench-callout-icon", "\u{26a1}" }
1330 span { "Interpreted recursion is capped at the shared MAX_CALL_DEPTH (2,500 frames); ackermann\u{2019}s deep self-recursion blows past it, so the interpreter runs it at a reduced m. Deep recursion only completes in compiled mode, where the optimizer collapses it." }
1331 }
1332 }
1333
1334 if interp_bars.is_empty() {
1335 div { class: "bench-chart-hint", "No interpreter result for {bench.name} (skipped, or not yet supported by the interpreter)." }
1336 } else {
1337 div { class: "bench-chart-hint",
1338 "Wall-clock time at n = {interp_n} \u{2014} shorter is faster."
1339 if let Some(s) = interp_active_speed {
1340 " The interpreter runs at {s:.2}x the speed of V8 here."
1341 }
1342 }
1343 div { class: "bench-chart",
1344 for (label, bar_class, median, _is_logos, _floored) in interp_bars.iter() {
1345 {
1346 let pct = (*median / interp_max * 100.0).min(100.0);
1347 let time_str = format_time(*median);
1348 let show_inside = pct > 15.0;
1349 rsx! {
1350 div { class: "bench-bar-row",
1351 div { class: "bench-bar-label", "{label}" }
1352 div { class: "bench-bar-track",
1353 div {
1354 class: "{bar_class}",
1355 style: "width: {pct:.1}%;",
1356 if show_inside {
1357 span { class: "bench-bar-time", "{time_str}" }
1358 }
1359 }
1360 }
1361 if !show_inside {
1362 span { class: "bench-bar-time-outside", "{time_str}" }
1363 }
1364 }
1365 }
1366 }
1367 }
1368 }
1369 }
1370 }
1371
1372 div { class: "bench-section", id: "source",
1374 div { class: "bench-section-title", "Source Code" }
1375 div { class: "bench-section-desc",
1376 "The LOGOS source and the Rust it compiles to. Switch an optimization off and watch its \u{201c}## No <X>\u{201d} decorator appear on the LOGOS source — and the generated Rust recompile live in your browser. With every optimization on you see the cached release build; disabling them all yields plain, boring Rust."
1377 }
1378
1379 div { class: "bench-opt-master",
1382 label {
1383 class: if all_opts_on { "bench-opt-toggle on" } else { "bench-opt-toggle off" },
1384 input {
1385 r#type: "checkbox",
1386 checked: all_opts_on,
1387 onchange: move |_| {
1388 let n = logicaffeine_compile::optimization::REGISTRY.len();
1389 let v = if opt_toggles().iter().all(|&b| b) { vec![false; n] } else { vec![true; n] };
1390 opt_toggles.set(v);
1391 live_rust.set(None);
1392 },
1393 }
1394 span { "All Optimizations" }
1395 }
1396 span { class: "bench-opt-hint",
1397 if base_fired().is_empty() {
1398 "analyzing which optimizations this program uses\u{2026}"
1399 } else {
1400 "{base_fired().len()} of {logicaffeine_compile::optimization::REGISTRY.len()} optimizations fire for this program"
1401 }
1402 }
1403 }
1404
1405 if all_opts_on {
1406 div { class: "bench-backend-trace",
1407 div { class: "bench-backend-trace-title",
1408 "Trace for {tab.fallback_label()}"
1409 }
1410 if optimizer_trace.is_empty()
1411 && lowering_trace.is_empty()
1412 && native_jit_trace.is_empty()
1413 && native_jit_compiled.is_empty()
1414 && native_jit_declines.is_empty()
1415 && native_jit_execution.is_empty()
1416 && decline_trace.is_empty()
1417 && fallback_trace.is_empty()
1418 {
1419 div { class: "bench-backend-trace-empty",
1420 "No staged trace is baked for this result yet. The next benchmark run will populate it."
1421 }
1422 } else {
1423 div { class: "bench-backend-trace-row",
1424 span { class: "bench-backend-trace-stage", "optimizer produced" }
1425 span { class: "bench-backend-trace-value",
1426 if optimizer_trace.is_empty() { "none" } else { "{optimizer_trace}" }
1427 }
1428 }
1429 div { class: "bench-backend-trace-row",
1430 span { class: "bench-backend-trace-stage", "backend lowered" }
1431 span { class: "bench-backend-trace-value",
1432 if lowering_trace.is_empty() { "none recorded" } else { "{lowering_trace}" }
1433 }
1434 }
1435 if !native_jit_compiled.is_empty() {
1436 div { class: "bench-backend-trace-row",
1437 span { class: "bench-backend-trace-stage", "JIT coverage" }
1438 span { class: "bench-backend-trace-value", "{native_jit_compiled}" }
1439 }
1440 }
1441 if !native_jit_trace.is_empty() {
1442 div { class: "bench-backend-trace-row",
1443 span { class: "bench-backend-trace-stage", "JIT native" }
1444 span { class: "bench-backend-trace-value", "{native_jit_trace}" }
1445 }
1446 }
1447 if !native_jit_execution.is_empty() {
1448 div { class: "bench-backend-trace-row",
1449 span { class: "bench-backend-trace-stage", "JIT executed" }
1450 span { class: "bench-backend-trace-value", "{native_jit_execution}" }
1451 }
1452 }
1453 if !native_jit_declines.is_empty() {
1454 div { class: "bench-backend-trace-row fallback",
1455 span { class: "bench-backend-trace-stage", "JIT declined" }
1456 span { class: "bench-backend-trace-value", "{native_jit_declines}" }
1457 }
1458 }
1459 if !decline_trace.is_empty() {
1460 div { class: "bench-backend-trace-row fallback",
1461 span { class: "bench-backend-trace-stage", "backend declined" }
1462 span { class: "bench-backend-trace-value", "{decline_trace}" }
1463 }
1464 }
1465 if !fallback_trace.is_empty() {
1466 div { class: "bench-backend-trace-row fallback",
1467 span { class: "bench-backend-trace-stage", "fallback" }
1468 span { class: "bench-backend-trace-value", "{fallback_trace}" }
1469 }
1470 }
1471 }
1472 }
1473 }
1474
1475 div { class: "bench-opt-toggles",
1485 for (node, visible) in opt_tree.iter().zip(tree_visible.iter().copied()) {
1486 if visible {
1487 {
1488 use logicaffeine_compile::optimization::OptRole;
1489 let opt = node.opt;
1490 let ri = opt as usize;
1491 let m = &logicaffeine_compile::optimization::REGISTRY[ri];
1492 let firing = fired_now().contains(&m.keyword);
1493 let needs = node.requires.iter().map(|o| o.meta().keyword).collect::<Vec<_>>().join(", ");
1494 let depends = node.depends_on.iter().map(|o| o.meta().keyword).collect::<Vec<_>>().join(", ");
1495 let blocks = node.preempts.iter().map(|o| o.meta().keyword).collect::<Vec<_>>().join(", ");
1496 let blocked_by = node.preempted_by.iter().map(|o| o.meta().keyword).collect::<Vec<_>>().join(", ");
1497 let blocks_now = preempted_now().iter()
1498 .filter(|(w, _)| *w == m.keyword)
1499 .map(|(_, l)| *l)
1500 .collect::<Vec<_>>()
1501 .join(", ");
1502 let cls = if !opt_tog[ri] { "bench-opt-toggle off" }
1503 else if firing { "bench-opt-toggle on firing" }
1504 else { match node.role {
1505 OptRole::Preempted => "bench-opt-toggle on preempted",
1506 OptRole::Enabler => "bench-opt-toggle on enabling",
1507 OptRole::Fired => "bench-opt-toggle on",
1508 } };
1509 let indent = node.depth * 22;
1510 let has_children = node.has_children;
1511 let is_expanded = expanded().get(ri).copied().unwrap_or(true);
1512 let chevron_cls = if is_expanded { "bench-tree-chevron open" } else { "bench-tree-chevron" };
1513 rsx! {
1514 div { class: "bench-tree-row", style: "padding-left: {indent}px;",
1515 if has_children {
1516 span {
1517 class: "{chevron_cls}",
1518 onclick: move |_| {
1519 let mut e = expanded();
1520 if ri < e.len() { e[ri] = !e[ri]; }
1521 expanded.set(e);
1522 },
1523 "\u{25b6}"
1524 }
1525 } else {
1526 span { class: "bench-tree-spacer" }
1527 }
1528 label { class: "{cls}", title: "{m.group}",
1529 input { r#type: "checkbox", checked: opt_tog[ri],
1530 onchange: move |_| {
1531 let toggles = opt_toggles();
1532 let turning_on = !toggles.get(ri).copied().unwrap_or(false);
1533 let mut cfg = config_from_toggles(&toggles);
1534 if turning_on {
1535 cfg.enable_with_requires(opt);
1536 } else {
1537 cfg.set(opt, false);
1538 }
1539 cfg.normalize();
1540 opt_toggles.set(toggles_from_config(&cfg));
1541 live_rust.set(None);
1542 },
1543 }
1544 span { "{m.label}" }
1545 if node.role == OptRole::Enabler {
1546 span { class: "bench-opt-rel enables", "enabler" }
1547 }
1548 if node.role == OptRole::Preempted && !blocked_by.is_empty() {
1549 span { class: "bench-opt-rel beaten", "blocked by {blocked_by} \u{00b7} fires if off" }
1550 }
1551 if !needs.is_empty() {
1552 span { class: "bench-opt-rel needs", "needs {needs}" }
1553 }
1554 if !depends.is_empty() {
1555 span { class: "bench-opt-rel depends", "depends on {depends}" }
1556 }
1557 if !blocks.is_empty() {
1558 span { class: "bench-opt-rel beats", "blocks {blocks}" }
1559 }
1560 if !blocks_now.is_empty() {
1561 span { class: "bench-opt-rel beats-now", "blocks {blocks_now} now" }
1562 }
1563 }
1564 }
1565 }
1566 }
1567 }
1568 }
1569 }
1570
1571 div { class: "bench-source",
1573 div { class: "bench-source-panel",
1574 div { class: "bench-source-header logos", "LOGOS" }
1575 div { class: "bench-source-code", "{opt_decorated}" }
1576 }
1577 div { class: "bench-source-panel",
1578 div { class: "bench-source-header rust bench-source-tabs", role: "tablist",
1579 for (t, label) in code_tabs.iter().cloned() {
1580 button {
1581 key: "{label}",
1582 class: if code_tab() == t { "bench-source-switch active" } else { "bench-source-switch" },
1583 role: "tab",
1584 "aria-selected": "{code_tab() == t}",
1585 onclick: move |_| code_tab.set(t),
1586 "{label}"
1587 }
1588 }
1589 }
1590 {code_body}
1591 }
1592 }
1593
1594 for (idx, lang_id) in source_langs.iter().enumerate() {
1596 {
1597 let src = get_source(bench_sources, lang_id);
1598 let label = lang_label(lang_id);
1599 let version = data.metadata.versions.get(*lang_id).map(|s| s.as_str()).unwrap_or("");
1600 let ext = lang_ext(lang_id);
1601 let file_url = format!("{}/blob/main/benchmarks/programs/{}/{}", GITHUB_REPO, bench.id, ext);
1602 let is_open = source_open()[idx];
1603 rsx! {
1604 div { class: "bench-lang-collapsible",
1605 div {
1606 class: "bench-lang-header",
1607 onclick: move |_| {
1608 let mut arr = source_open();
1609 arr[idx] = !arr[idx];
1610 source_open.set(arr);
1611 },
1612 span { class: swatch_class(lang_id) }
1613 span { class: "bench-lang-name", "{label}" }
1614 span { class: "bench-lang-version", "{version}" }
1615 a {
1616 class: "bench-lang-link",
1617 href: "{file_url}",
1618 target: "_blank",
1619 onclick: move |e: Event<MouseData>| e.stop_propagation(),
1620 "View on GitHub \u{2192}"
1621 }
1622 span {
1623 class: if is_open { "bench-collapsible-chevron open" } else { "bench-collapsible-chevron" },
1624 "\u{25b6}"
1625 }
1626 }
1627 div {
1628 class: if is_open { "bench-lang-code open" } else { "bench-lang-code" },
1629 "{src}"
1630 }
1631 }
1632 }
1633 }
1634 }
1635 }
1636
1637 div { class: "bench-section", id: "compilation",
1639 div { class: "bench-section-title", "Compilation Times" }
1640 div { class: "bench-section-desc",
1641 "Time to compile each benchmark from source, with the same flags the timed builds use. "
1642 "LOGOS compiles through Rust or through C, so its bars include rustc or the C compiler at full optimization."
1643 }
1644
1645 div { class: "bench-chart",
1646 for (name, mean, _stddev, is_largo) in compile_entries.iter() {
1647 {
1648 let pct = (*mean / compile_max * 100.0).min(100.0);
1649 let time_str = format_time(*mean);
1650 let show_inside = pct > 15.0;
1651 let bar_class = match *name {
1652 "logos_release" => "bench-bar-fill bench-bar-logos-rust",
1653 "logos_c" => "bench-bar-fill bench-bar-logos-c",
1654 "logos_cbc" => "bench-bar-fill bench-bar-logos-cbc",
1655 _ if *is_largo => "bench-bar-fill bench-bar-logos-jit",
1656 _ => "bench-bar-fill bench-bar-other",
1657 };
1658 let display_name = data.metadata.compiler_label(name);
1659 rsx! {
1660 div { class: "bench-bar-row",
1661 div { class: "bench-bar-label", "{display_name}" }
1662 div { class: "bench-bar-track",
1663 div {
1664 class: "{bar_class}",
1665 style: "width: {pct:.1}%;",
1666 if show_inside {
1667 span { class: "bench-bar-time", "{time_str}" }
1668 }
1669 }
1670 }
1671 if !show_inside {
1672 span { class: "bench-bar-time-outside", "{time_str}" }
1673 }
1674 }
1675 }
1676 }
1677 }
1678 }
1679
1680 button {
1682 class: "bench-collapsible-btn",
1683 onclick: move |_| compile_detail_open.set(!compile_detail_open()),
1684 span {
1685 class: if compile_detail_open() { "bench-collapsible-chevron open" } else { "bench-collapsible-chevron" },
1686 "\u{25b6}"
1687 }
1688 "Detailed Compilation Data"
1689 }
1690 div {
1691 class: if compile_detail_open() { "bench-collapsible-body open" } else { "bench-collapsible-body" },
1692 table { class: "bench-compile-table",
1693 thead {
1694 tr {
1695 th { "Compiler" }
1696 th { "Mean" }
1697 th { "StdDev" }
1698 }
1699 }
1700 tbody {
1701 for (name, mean, stddev, is_largo) in compile_entries.iter() {
1702 tr {
1703 class: if *is_largo { "highlight" } else { "" },
1704 td { class: "compiler-name", "{data.metadata.compiler_label(name)}" }
1705 td { "{format_time(*mean)}" }
1706 td { "\u{00b1}{format_time(*stddev)}" }
1707 }
1708 }
1709 }
1710 }
1711 }
1712 }
1713
1714 div { class: "bench-section", id: "summary",
1716 div { class: "bench-section-title", "Cross-Benchmark Summary" }
1717 div { class: "bench-section-desc", "Geometric-mean speed vs C across all {data.benchmarks.len()} benchmarks (bars proportional to speed; higher is faster)." }
1718
1719 BarChart { groups: summary_groups(data), unit: BarUnit::SpeedOfC }
1720 }
1721
1722 div { class: "bench-section", id: "methodology",
1724 button {
1725 class: "bench-collapsible-btn bench-methodology-toggle",
1726 onclick: move |_| methodology_open.set(!methodology_open()),
1727 span {
1728 class: if methodology_open() { "bench-collapsible-chevron open" } else { "bench-collapsible-chevron" },
1729 "\u{25b6}"
1730 }
1731 span { class: "bench-methodology-title", "Methodology" }
1732 }
1733 div {
1734 class: if methodology_open() { "bench-collapsible-body open" } else { "bench-collapsible-body" },
1735 div { class: "bench-methodology",
1736 ul {
1737 li { "Each benchmark measured with hyperfine ({data.metadata.runs.unwrap_or(20)} runs, {data.metadata.warmup.unwrap_or(5)} warmup), pinned to the performance cores on a machine checked quiet first; the bars show the median, and every ratio and geometric mean uses the mean." }
1738 li { "CPU: {data.metadata.cpu}." }
1739 li { "OS: {data.metadata.os}." }
1740 li { "Every implementation runs the same algorithm, with its sorts and hash tables hand-rolled in every language, and produces identical output, verified byte for byte before anything is timed." }
1741 li { "Every compiled language is built at its fastest release setting for this CPU, with the commands below; C, C++ and Nim compile with floating-point contraction off, as every other language rounds each operation." }
1742 li { "With the algorithm unchanged, the LOGOS compiler also chooses storage the other programs spell out: an Int it proves fits in 32 bits is stored in 32 bits, a local Seq of Bool is held one bit per item, and the remainder of a value proven below twice its divisor is one subtraction. These count as the same algorithm." }
1743 li { "Two geometric means are reported vs C: the headline keeps all {data.benchmarks.len()} benchmarks; the apples-to-apples figure removes the {collapse_count} where the LOGOS compiler collapses the algorithm (\u{26a1}). Every collapse is auditable in the generated Rust per benchmark." }
1744 li { "The Interpreter-vs-V8 section is a separate peer comparison (LOGOS bytecode VM + JIT against Node/V8) at interpreter-calibrated sizes, so its n differs from the compiled section." }
1745 }
1746
1747 h3 { "Compiler Versions" }
1748 table { class: "bench-version-table",
1749 thead {
1750 tr {
1751 th { "Language" }
1752 th { "Version" }
1753 }
1754 }
1755 tbody {
1756 for (lang_id, version) in data.metadata.versions.iter() {
1757 tr {
1758 td { "{lang_label(lang_id)}" }
1759 td { "{version}" }
1760 }
1761 }
1762 }
1763 }
1764
1765 h3 { "Build commands" }
1766 table { class: "bench-version-table",
1767 thead {
1768 tr {
1769 th { "Language" }
1770 th { "Built and run with" }
1771 }
1772 }
1773 tbody {
1774 for lang in data.languages.iter() {
1775 if let Some(command) = data.metadata.build_commands.get(&lang.id) {
1776 tr {
1777 td { "{lang.label}" }
1778 td { code { "{command}" } }
1779 }
1780 }
1781 }
1782 }
1783 }
1784
1785 h3 { "Links" }
1786 ul {
1787 li {
1788 a { href: "{runsh_url}", target: "_blank", "benchmarks/run.sh" }
1789 " \u{2014} benchmark runner script"
1790 }
1791 li {
1792 a { href: "{raw_json_url}", target: "_blank", "results/latest.json" }
1793 " \u{2014} raw benchmark data"
1794 }
1795 li {
1796 a { href: "{history_url}", target: "_blank", "results/history/" }
1797 " \u{2014} historical results by version"
1798 }
1799 li {
1800 a { href: "{bench_dir_url}", target: "_blank", "benchmarks/" }
1801 " \u{2014} all benchmark source code"
1802 }
1803 li {
1804 a { href: "/data/flamegraphs.pdf", download: "logos-flamegraphs.pdf", "profile/flamegraphs.pdf" }
1805 " \u{2014} CPU-profile flamegraph breakdowns ({data.benchmarks.len()} benchmarks, LOGOS vs C)"
1806 }
1807 }
1808 }
1809 }
1810 }
1811 }
1812 }
1813 if bench_tab() == BenchTab::Solver {
1814 div { class: "bench-content",
1815 SolverSection {}
1816 }
1817 }
1818 if bench_tab() == BenchTab::Codec {
1819 div { class: "bench-content",
1820 CodecSection {}
1821 }
1822 }
1823
1824 Footer {}
1825 }
1826 }
1827}