From 3e4bae1a98619702b052357cc233952c68836037 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Tue, 28 Jul 2026 10:00:04 +0545 Subject: [PATCH] perf: cache failed D-Bus introspection paths Add _dead set to _IntrospectionCache to track paths that timeout. Failed introspections are skipped on future lookups, reducing timeout blocks from 300-500ms to near-zero. --- src/window/globalmenu/service.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/window/globalmenu/service.py b/src/window/globalmenu/service.py index 92fd7cc..1f3fc44 100644 --- a/src/window/globalmenu/service.py +++ b/src/window/globalmenu/service.py @@ -48,6 +48,7 @@ class _IntrospectionCache: def __init__(self): self._cache: dict[str, str] = {} + self._dead: set[str] = set() self._lock = threading.Lock() def get(self, service: str, path: str, bus, timeout: int) -> str: @@ -55,12 +56,17 @@ class _IntrospectionCache: return "" key = f"{service}:{path}" with self._lock: + if key in self._dead: + return "" cached = self._cache.get(key) if cached is not None: return cached xml = _dbus_introspect(bus, service, path, timeout) with self._lock: - self._cache[key] = xml + if xml: + self._cache[key] = xml + else: + self._dead.add(key) return xml def invalidate(self, service: str):