#!/usr/bin/env python3 """Compare per-tile passage candidate-list sizes for L109 and L112.""" from __future__ import annotations import json import math import re import statistics import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l112/candidate-lists" DATA = ROOT / "Standalone/data/owner_world.json" BINARIES = { "L109": ROOT / "Saved/Linux/l109/bin-final/VoxelForgeCoreHeadless-l109-clang", "L112": ROOT / "Saved/Linux/l112/bin-clang/VoxelForgeCoreHeadless-l112-clang", } CAMERAS = { 0: (8.0, 16.0, -372.2626953125), 1: (25.8369140625, 3.19921875, -737.0), 2: (19.166015625, -14.2001953125, -753.3740234375), 3: (-20.0625, -5.068359375, -900.353515625), } LIST = re.compile(r"^\[PassageComposerTile\].*?features=(\d+) route_candidates=(\d+)", re.M) def percentile(values: list[int], fraction: float) -> int: ordered = sorted(values) if not ordered: return 0 return ordered[min(len(ordered) - 1, max(0, math.ceil(fraction * len(ordered)) - 1))] def run(strate: int, version: str) -> dict: OUT.mkdir(parents=True, exist_ok=True) log = OUT / f"{version}-s{strate}.log" camera = ",".join(f"{v:.12f}" for v in CAMERAS[strate]) + ",0,0" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", "timeout", "1740s", str(BINARIES[version]), str(DATA), "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--workers=12", "--clip-radius=3", "--max-clip-level=8", "--max-level=8", f"--camera={camera}", "--profile-passage-composer", "--stream-scheduler-policy=3", ] started = time.monotonic() with log.open("w", encoding="utf-8") as stream: result = subprocess.run(command, cwd=ROOT, stdout=stream, stderr=subprocess.STDOUT, check=False, timeout=1740) output = log.read_text(encoding="utf-8", errors="replace") features = [int(row[0]) for row in LIST.findall(output)] routes = [int(row[1]) for row in LIST.findall(output)] if result.returncode or not features: raise SystemExit(f"candidate-list profile missing: {log}; exit={result.returncode}") row = { "strate": strate, "version": version, "profiled_tiles": len(features), "feature_candidates": {"sum": sum(features), "min": min(features), "median": statistics.median(features), "p95": percentile(features, .95), "max": max(features)}, "route_segment_candidates": {"sum": sum(routes), "min": min(routes), "median": statistics.median(routes), "p95": percentile(routes, .95), "max": max(routes)}, "elapsed_s": round(time.monotonic() - started, 3), "log": str(log.relative_to(ROOT)), } print("[L112CandidateLists] " + json.dumps(row, sort_keys=True), flush=True) return row def main() -> int: if any(not path.is_file() for path in (*BINARIES.values(), DATA)): raise SystemExit("missing L109/L112 candidate-list input") rows = [run(strate, version) for strate in range(4) for version in ("L109", "L112")] (OUT / "summary.json").write_text(json.dumps(rows, indent=2) + "\n", encoding="utf-8") return 0 if __name__ == "__main__": raise SystemExit(main())