From 7eded537d6b69c98e4f8476360feaa3359395b74 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 22 Oct 2026 21:45:57 +0200 Subject: [PATCH 1/2] perf_bench: wait for Horizon to actually load before timing a scene Right after a teleport, and at spawn, Horizon v2026.10.22.04 reports nothing queued and steady chunk counts for over a second before it starts loading. wait_loaded() took that for "loaded" and stopped the clock with 0 to 3 sections meshed (load 0.1 s), so the flights ran over empty terrain and the frame rates meant nothing. Now the counts must change once since the wait began (or stay at the full view for 5 s), and the resident chunks must reach 80% of the view circle (pi x RD^2), before a steady second counts as loaded. Measured with it on the Mac mini and the ThinkPad for the website's Benchmarks page (#1274). At RD 32 a 4-thread laptop needs --timeout above the default 300 s. Co-Authored-By: Claude Opus 5.5 --- tools/perf_bench.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/perf_bench.py b/tools/perf_bench.py index eb6b3fda2..bf5ee5582 100644 --- a/tools/perf_bench.py +++ b/tools/perf_bench.py @@ -307,7 +307,12 @@ def poll(control, check, limit, interval=0.05): QUIET_MESHES_PER_S = 100 -def wait_loaded(control, near, limit): +def view_chunks(distance): + """80% of the view circle (pi x RD^2): Horizon keeps 637 columns at RD 12 and 3725 at RD 32.""" + return int(0.8 * math.pi * distance ** 2) + + +def wait_loaded(control, near, limit, min_chunks=0): """Waits until the player is spawned (near(position)), nothing is queued, the resident and generated chunk counts have not changed for a second, as the vanilla driver does, and the last sections are drawn; returns when the last @@ -320,6 +325,10 @@ def wait_loaded(control, near, limit): already taken, and sections waiting for their neighbours' light.)""" deadline = time.time() + limit last, changed, previous, meshing = None, time.time(), None, time.time() + # Right after a teleport (and at spawn) Horizon reports nothing queued and steady counts for over a second + # before it starts loading: the counts must change once, or stay full for 5 s, and the resident chunks reach + # min_chunks, before "steady" means loaded. + first, moved, began = None, False, time.time() while time.time() < deadline: try: s = control("status", timeout=10) @@ -331,6 +340,12 @@ def wait_loaded(control, near, limit): last, changed, previous, meshing = None, now, None, now else: counts = (s["chunks"], s["generated_chunks"]) + first = first or counts + moved = moved or counts != first or (s["chunks"] >= min_chunks > 0 and now - began > 5) + if not moved or s["chunks"] < min_chunks: + last, changed, previous, meshing = None, now, None, now + time.sleep(0.05) + continue if counts != last: last, changed = counts, now stages = s.get("streaming") @@ -392,7 +407,7 @@ def run_horizon(args, distance): result["renderer"] = title["renderer"] result["startup"] = {"title_s": at - started} control(f"open {WORLD} {SEED} creative") - result["startup"]["world_s"] = wait_loaded(control, lambda p: True, args.timeout) - started + result["startup"]["world_s"] = wait_loaded(control, lambda p: True, args.timeout, view_chunks(distance)) - started for name, start, end, pitch in scene_list(args): control("time 6000") meshed = control("status")["meshed_sections"] @@ -402,7 +417,7 @@ def run_horizon(args, distance): control("fly {0} {1} {2} {0} {1} {2} 0.1 {3}".format(*start, pitch)) control(f"look {yaw(start, end):.3f} {pitch}") near = lambda p: sum((a - b) ** 2 for a, b in zip(p, start)) < 4.0 - scene = {"load_s": wait_loaded(control, near, args.timeout) - tp} + scene = {"load_s": wait_loaded(control, near, args.timeout, view_chunks(distance)) - tp} # Section meshes built while loading and while flying (Horizon only). loaded_meshes = control("status")["meshed_sections"] scene["meshes_load"] = loaded_meshes - meshed From 9e1c3ec860c0961385a2f2b77d13d4627b9ea833 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 22 Oct 2026 21:51:16 +0200 Subject: [PATCH 2/2] perf_bench: the readiness gate only with a chunk target; a test for the quiet start Without min_chunks (the old call) wait_loaded behaves as before, which tests/test_perf_bench.py's old-builds case relies on. Co-Authored-By: Claude Opus 5.5 --- tests/test_perf_bench.py | 16 ++++++++++++++-- tools/perf_bench.py | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/test_perf_bench.py b/tests/test_perf_bench.py index 4729c5e20..ea074442e 100644 --- a/tests/test_perf_bench.py +++ b/tests/test_perf_bench.py @@ -50,7 +50,7 @@ if __name__ == "__main__": class WaitLoadedTests(unittest.TestCase): """wait_loaded on a scripted game with a fake clock: one status per 50 ms poll.""" - def run_script(self, statuses): + def run_script(self, statuses, min_chunks=0): import tools.perf_bench as pb clock = [0.0] it = iter(statuses) @@ -62,7 +62,7 @@ class WaitLoadedTests(unittest.TestCase): pb.time.time = lambda: clock[0] pb.time.sleep = lambda s: clock.__setitem__(0, clock[0] + s) try: - return pb.wait_loaded(control, lambda p: True, 60) + return pb.wait_loaded(control, lambda p: True, 60, min_chunks) finally: pb.time.time, pb.time.sleep = real_time, real_sleep @@ -86,3 +86,15 @@ class WaitLoadedTests(unittest.TestCase): busy = [self.status(901, 1000 * i) for i in range(20)] quiet = [self.status(901, 20000 + i) for i in range(40)] self.assertAlmostEqual(self.run_script(busy + quiet), 1.0, places=6) + + def test_a_quiet_start_is_not_a_load(self): + # Right after a teleport Horizon reports steady counts and nothing queued for 1.5 s before it loads: + # with a target the clock runs on until the chunks are there and the meshing has gone quiet. + idle = [self.status(3, 0, stages=0) for _ in range(30)] + loading = [self.status(30 * (i + 1), 500 * i, stages=500) for i in range(20)] + tail = [self.status(600, 10000, stages=0) for _ in range(60)] + took = self.run_script(idle + loading + tail, min_chunks=500) + self.assertGreater(took, 2.4) + self.assertLess(took, 4.0) + # Without one (the old call), the quiet start ends the wait at once. + self.assertLess(self.run_script(idle + loading + tail), 1.6) diff --git a/tools/perf_bench.py b/tools/perf_bench.py index bf5ee5582..6ff6b8052 100644 --- a/tools/perf_bench.py +++ b/tools/perf_bench.py @@ -342,7 +342,7 @@ def wait_loaded(control, near, limit, min_chunks=0): counts = (s["chunks"], s["generated_chunks"]) first = first or counts moved = moved or counts != first or (s["chunks"] >= min_chunks > 0 and now - began > 5) - if not moved or s["chunks"] < min_chunks: + if min_chunks and (not moved or s["chunks"] < min_chunks): last, changed, previous, meshing = None, now, None, now time.sleep(0.05) continue