perf: add correctness-verified marqdo.perf.v2 sampler
ci/woodpecker/push/woodpecker Pipeline was canceled
CI / fmt + clippy + test (Linux x86_64) (push) Canceled after 0s
CI / schema instance validation + consumers (push) Canceled after 0s
CI / runtime contract (macos-latest) (push) Canceled after 0s
CI / runtime contract (windows-latest) (push) Canceled after 0s
CI / release candidate artifact (macos-latest) (push) Canceled after 0s
CI / release candidate artifact (ubuntu-latest) (push) Canceled after 0s
Linux strict security lane (G-C) / strict isolation escape matrix (push) Canceled after 0s

Replace the three-run baseline profile with tools/perf/runner.py: one fixed
release binary, per-child rusage via posix_spawn/wait4, 5 warmups and 20
samples by default, SHA-derived interleaved order, p50/p95/MAD, CPU user/sys
and peak RSS. Every warmup output is normalized and compared with a committed
wire digest before timing; a mismatch is CORRECTNESS_FAIL, never a fast
sample. Short or unapproved-host runs are SMOKE, and baselines from another
platform_id/profile are refused.

Add workloads.json, expected digests for nine existing workloads, a dedicated
fixed-node workflow (manual, self-hosted, requires --cpu-list), and
docs/performance.md. bench.py stays as a compatibility shim. This is step 5 of
the CI/security RFC (B08).
This commit is contained in:
cflmy committed 2026-11-21 17:28:05 +08:00
1 parent 990e984ab6
commit d2267e912a
16 files changed
+1615 -93

No files matched your search

+11 -93
View File
@@ -1,100 +1,18 @@
#!/usr/bin/env python3
"""Reproducible P6 baseline profile for selected .mq.md workloads.
"""Deprecated alias for tools/perf/runner.py.
Builds the release CLI, runs each workload three times through /usr/bin/time,
and writes a JSON report with wall seconds and peak RSS. This is a baseline
profile, not a claim that P6 optimization is complete.
The old three-run profile did not verify workload correctness and is not a
performance gate. Use runner.py; this wrapper keeps old local commands working.
"""
import json
import os
import statistics
import subprocess
import runpy
import sys
import tempfile
import time
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
target_dir = Path(os.environ.get("CARGO_TARGET_DIR", ROOT / "target"))
if not target_dir.is_absolute():
target_dir = ROOT / target_dir
BIN = target_dir / "release" / "marqdo"
WORKLOADS = [
("allocator-free-list", "tests/conformance/semantics/55-first-fit-free-list-allocator.mq.md"),
("json-parser", "tests/conformance/semantics/62-json-array-parser.mq.md"),
("table-sort", "tests/conformance/semantics/65-table-sort-stdlib.mq.md"),
("bytecode-vm", "tests/conformance/semantics/63-memory-bytecode-vm.mq.md"),
("matrix-multiply", "tests/conformance/semantics/70-matrix-multiply.mq.md"),
("http-parser", "tests/conformance/semantics/71-http-parser.mq.md"),
("stdlib-print-demo", "stdlib/demo.mq.md"),
]
def run_once(relative: str) -> dict:
with tempfile.NamedTemporaryFile("r", delete=False) as handle:
time_path = handle.name
command = [
"/usr/bin/time",
"-f",
"%e %M",
"-o",
time_path,
str(BIN),
"run",
relative,
"--json",
]
env = dict(os.environ)
env["MARQDO_STDLIB_DIR"] = str(ROOT / "stdlib")
started = time.perf_counter()
output = subprocess.run(
command, cwd=ROOT, env=env, capture_output=True, text=True, timeout=120
)
elapsed = time.perf_counter() - started
timing = Path(time_path).read_text().split()
Path(time_path).unlink(missing_ok=True)
if output.returncode != 0:
raise RuntimeError(f"{relative} failed: {output.stderr}")
report = json.loads(output.stdout)
if not report.get("success"):
raise RuntimeError(f"{relative} reported failure")
return {
"seconds": elapsed,
"max_rss_kb": int(timing[1]),
}
def main() -> int:
subprocess.run(
["cargo", "build", "--release", "-p", "marqdo-cli"],
cwd=ROOT,
check=True,
)
report = {
"schema": "marqdo.perf-baseline",
"schema_version": 1,
"binary": str(BIN.relative_to(ROOT)),
"iterations": 3,
"workloads": [],
}
for name, relative in WORKLOADS:
runs = [run_once(relative) for _ in range(3)]
report["workloads"].append(
{
"name": name,
"source": relative,
"seconds_median": round(statistics.median(r["seconds"] for r in runs), 4),
"seconds_min": min(r["seconds"] for r in runs),
"max_rss_kb_median": int(
statistics.median(r["max_rss_kb"] for r in runs)
),
}
)
json.dump(report, sys.stdout, ensure_ascii=False, indent=2)
sys.stdout.write("\n")
return 0
if __name__ == "__main__":
raise SystemExit(main())
print(
"warning: tools/perf/bench.py is a compatibility shim; "
"use tools/perf/runner.py for correctness-verified measurements",
file=sys.stderr,
)
sys.argv[0] = str(Path(__file__).with_name("runner.py"))
runpy.run_path(sys.argv[0], run_name="__main__")