perf(steam): decode requested appinfo records only

Avoid decoding every app when Start without Steam resolves one game launch. Use wanted-app selection in the single-game helpers while keeping the existing field decoder and full-reader default for bulk callers.

Track partial coverage separately from complete results, share one immutable byte snapshot for incremental queries, and keep timestamp invalidation and warm hits. Preserve the last valid duplicate record and release the raw snapshot after a full decode.

Add format/cache/structural-budget and launch-resolution regressions, reuse the existing binary fixture encoder, and document the host-only performance scope.
This commit is contained in:
dddms authored and Kurt Himebauch committed 2026-11-05 11:17:03 -05:00
1 parent 92a588ea16
commit e72cddccd9
5 files changed
+290 -12

No files matched your search

@@ -351,7 +351,7 @@ def steam_launch(appid, root):
library, install = steam_install(appid, root)
if not install or not os.path.isdir(install):
return None
entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf")).get(str(appid), {})
entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf"), wanted={str(appid)}).get(str(appid), {})
options = [option for option in entry.get("launch_options", ())
if not option["betakey"] and (not option["oslist"] or "windows" in option["oslist"])]
options.sort(key=lambda option: (option["type"] not in ("", "default", "none"),
@@ -376,7 +376,7 @@ def shortcut_target(appid, program, start, root):
def steam_launches(target, program, root):
if target.kind != "steam":
return False
entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf")).get(target.appid, {})
entry = compat()["appinfo_entries"](os.path.join(root, "appcache", "appinfo.vdf"), wanted={target.appid}).get(target.appid, {})
return os.path.relpath(program, target.install).replace(os.sep, "/").lower() in entry.get("launch", ())
@@ -777,20 +777,32 @@ def launch_options(config):
return found
def appinfo_entries(path):
def appinfo_entries(path, wanted=None):
"""Read metadata for all apps, or only the requested app-id strings."""
import struct
if wanted is not None:
wanted = set(wanted)
if not wanted:
return {}
try:
stamp = os.stat(path).st_mtime_ns
except OSError:
return {}
cached = APPINFO_CACHE.get(path)
if cached and cached[0] == stamp:
return cached[1]
try:
with open(path, "rb") as f:
data = f.read()
except OSError:
return {}
covered = cached[2]
if covered is None or (wanted is not None and wanted <= covered):
return cached[1] if wanted is None else {app: cached[1][app] for app in wanted if app in cached[1]}
data = cached[3]
needed = None if wanted is None else wanted - covered
else:
cached = None
needed = wanted
try:
with open(path, "rb") as f:
data = f.read()
except OSError:
return {}
if len(data) < 8:
return {}
magic = struct.unpack_from("<I", data, 0)[0]
@@ -852,6 +864,8 @@ def appinfo_entries(path):
break
start = offset + 8
offset = start + size
if needed is not None and str(app) not in needed:
continue
try:
info = section(start + header)[0].get("appinfo", {})
except (ValueError, IndexError, struct.error):
@@ -876,8 +890,14 @@ def appinfo_entries(path):
entry["app_mappings"] = {str(m.get("appid", key)): str(m.get("tool", "")) for key, m in mappings.items()
if isinstance(m, dict)} if isinstance(mappings, dict) else {}
found[str(app)] = entry
APPINFO_CACHE[path] = (stamp, found)
return found
covered = wanted
if cached is not None and wanted is not None:
cached[1].update(found)
found = cached[1]
covered = cached[2] | wanted
# None coverage is complete; partial entries keep one immutable file snapshot.
APPINFO_CACHE[path] = (stamp, found, covered, data if covered is not None else None)
return found if wanted is None else {app: found[app] for app in wanted if app in found}
def appinfo_platforms(path, wanted):