From 3d6fe483408cde2580e9718039d6586915df01fb Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 17 Jun 2026 02:31:56 -0700 Subject: [PATCH] [eric] perf: no-op swarm-debug debug() in packaged mode (removes ~17s cold-start scan) - first debug() call instantiated Debugleton -> recursive os.scandir project scan on the boot path (~17s cold, ~80ms warm) - early-return when OPENSWARM_PACKAGED=1; dev keeps the full debugger; debug() returns None so callers are unaffected - validated: with the flag debug() no-ops (no scan); debugger is pip-installed from repo/debugger at build so this ships --- debugger/debug.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/debugger/debug.py b/debugger/debug.py index bef85d4a..f8568ed2 100644 --- a/debugger/debug.py +++ b/debugger/debug.py @@ -7,6 +7,15 @@ from debugger_backend.color_adjuster import rgb_to_ansi, bold_and_italicize_text from debugger_backend.debug_arg_parser import is_text, is_error def debug(*args, mode:str='debug', override_max_chars:bool=False): + # Packaged/prod no-op: this frame-aware debugger is a dev tool, and its first + # call instantiates Debugleton() -> a recursive os.scandir project scan that + # runs synchronously on the backend's startup path. On a cold launch (uncached + # filesystem) that scan cost ~17s of the backend-http-ready time; warm it is + # ~80ms. Skipping it in the packaged build removes the cold cost entirely. Dev + # (OPENSWARM_PACKAGED unset) keeps the full debugger. Safe: debug() returns + # None and every caller ignores the return value. + if os.environ.get("OPENSWARM_PACKAGED") == "1": + return frame = inspect.currentframe().f_back code = frame.f_code line_no = frame.f_lineno