makepad/libs/relax/compiler/tests/live/bench_stream_rust.py
Admin b22a714840 makepad run: the Rust JIT (libs/relax) and makepad-remote
The JIT that runs makepad apps from source: lexer, front end, type checker,
lazy borrow checker (Gandalf; `--check-first` opts in), codegen, session and
warm/cold caches keyed by compiler stamp, provided crates bound late,
startup images, live patching. User-facing name is `makepad run` (binary
`makepad`, MAKEPAD_RUN_* env, ~/.makepad-run); libs/relax stays the internal
library name. `makepad check` reports rustc-style diagnostics with rustc
error codes and checks a whole workspace (`--workspace`). Runs on macOS,
Linux, Windows and Android. makepad-remote: one tool schema for apps and the
WM (app/1): grabs, captures, traces, frame profiles and tweaks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 12:26:21 +02:00

44 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Measure compose_partial on 3,000 lines using the release makepad binary argument.
Run from libs/relax/compiler with MAKEPAD_RUN_STD=$PWD/std MAKEPAD_RUN_CACHE=0. No build or download.
"""
import os
import pathlib
import re
import statistics
import subprocess
import sys
import tempfile
def main():
with tempfile.TemporaryDirectory(prefix="relax-stream-bench-") as tmp:
root = pathlib.Path(tmp)
# Many separate items exercise identity matching, rather than one large body.
items = "".join(f"fn f{i}() -> i32 {{\n {i}\n}}\n" for i in range(999))
source = items + '#[test]\nfn run() {\n println!("out {}", f0()); }\n'
assert len(source.splitlines()) == 3000
initial = root / "v0.rs"
initial.write_text(source)
versions = []
for i in range(1, 41):
path = root / f"v{i}.rs"
# The first item changes; the final item has only its header so far.
path.write_text(source.replace(" 0\n", f" {i}\n", 1).split("#[test]")[0] + "#[test]\nfn ru")
versions.append(str(path))
env = dict(os.environ, MAKEPAD_RUN_CACHE="0", MAKEPAD_RUN_STREAM_TIMING="1")
run = subprocess.run([sys.argv[1], "live", str(initial), *versions],
env=env, text=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, timeout=180)
costs = [float(x) for x in re.findall(r"makepad-run stream: compose_partial \d+ bytes ([\d.]+) ms", run.stdout)]
if run.returncode or len(costs) != len(versions) or "rung=refuse" in run.stdout or "rung=restart" in run.stdout:
sys.exit(run.stdout)
ordered = sorted(costs)
print(f"compose_partial: 3,000 lines, {len(costs)} deltas; "
f"median {statistics.median(costs):.3f} ms, "
f"p95 {ordered[round((len(costs)-1)*.95)]:.3f} ms, max {max(costs):.3f} ms")
if __name__ == "__main__":
main()