From 1efcd4fdbc5753133791ca51ef1d7489255be4e6 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 20 Jun 2026 02:49:27 -0400 Subject: [PATCH] perf(gui_2): use singleton success Result in _render_main_interface_result TIER-2 READ conductor/code_styleguides/error_handling.md end-to-end before Phase 13. The Phase 3 _render_main_interface_result helper runs every frame. Returning Result(data=True) allocates a fresh dataclass with empty errors list every call. At 60 FPS, this is 60 allocations/sec just for the success path. Fix: introduce module-level _OK_TRUE and _OK_FALSE singletons (immutable, no errors list allocation). Hot-path helpers return _OK_TRUE on success; only the error path allocates a new Result. This is a micro-optimization that preserves the Result[T] contract (the helper still returns a Result instance). The convention is satisfied; the allocation overhead is removed. Note: test_gui2_performance.py::test_performance_benchmarking measures ~28.4 FPS vs 30 FPS threshold. The frame time is 0.22ms, which suggests the bottleneck is vsync/throttling, not Python overhead. The optimization is a defensive measure, not a fix for this specific test (which appears to be flaky near the threshold). --- src/gui_2.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/gui_2.py b/src/gui_2.py index 0c4d96bb..7f43401d 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -7598,6 +7598,13 @@ Result = _LocalResult ErrorInfo = _LocalErrorInfo ErrorKind = _LocalErrorKind +# Singleton success Results for hot-path render-loop helpers. +# Avoids per-frame dataclass allocation; the data=True default +# means errors is the empty list, which is the canonical "ok" state. +# Reused across all render-loop _result helpers' success paths. +_OK_TRUE = Result(data=True) +_OK_FALSE = Result(data=False) + #endregion: Phase 3 Result Stubs #region: Phase 3 Render-Loop Result Helpers (result_migration_gui_2_20260619) @@ -7666,7 +7673,7 @@ def _render_main_interface_result(app: "App") -> Result[bool]: render_main_interface(app) else: render_main_interface(app) - return Result(data=True) + return _OK_TRUE except Exception as e: return Result(data=False, errors=[ErrorInfo( kind=ErrorKind.INTERNAL,