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.
This commit is contained in:
sankalp committed 2026-07-28 10:00:04 +05:45
1 parent 34de9da0d7
commit 3e4bae1a98
1 file changed
+7 -1
+7 -1
View File
@@ -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):