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:
1 file changed
+7
-1
@@ -48,6 +48,7 @@ class _IntrospectionCache:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._cache: dict[str, str] = {}
|
self._cache: dict[str, str] = {}
|
||||||
|
self._dead: set[str] = set()
|
||||||
self._lock = threading.Lock()
|
self._lock = threading.Lock()
|
||||||
|
|
||||||
def get(self, service: str, path: str, bus, timeout: int) -> str:
|
def get(self, service: str, path: str, bus, timeout: int) -> str:
|
||||||
@@ -55,12 +56,17 @@ class _IntrospectionCache:
|
|||||||
return ""
|
return ""
|
||||||
key = f"{service}:{path}"
|
key = f"{service}:{path}"
|
||||||
with self._lock:
|
with self._lock:
|
||||||
|
if key in self._dead:
|
||||||
|
return ""
|
||||||
cached = self._cache.get(key)
|
cached = self._cache.get(key)
|
||||||
if cached is not None:
|
if cached is not None:
|
||||||
return cached
|
return cached
|
||||||
xml = _dbus_introspect(bus, service, path, timeout)
|
xml = _dbus_introspect(bus, service, path, timeout)
|
||||||
with self._lock:
|
with self._lock:
|
||||||
self._cache[key] = xml
|
if xml:
|
||||||
|
self._cache[key] = xml
|
||||||
|
else:
|
||||||
|
self._dead.add(key)
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
def invalidate(self, service: str):
|
def invalidate(self, service: str):
|
||||||
|
|||||||
Reference in new issue
Block a user