perf(dl): parallelise mux, licensing, and vault lookups; size the shared pool

Grow the service session pool to downloads * workers before track downloads, run mkvmerge jobs concurrently (muxing.concurrency, default 4), lock DRM preparation per key set instead of globally, and query local vaults first then remote vaults together.
This commit is contained in:
imSp4rky
2026-08-20 11:24:12 -06:00
parent 8b10b793e2
commit 537a1dc973
10 changed files with 199 additions and 41 deletions
+2 -2
View File
@@ -1,3 +1,3 @@
from .requests import format_speed, parse_speed_limit, requests, set_speed_limit
from .requests import default_max_workers, format_speed, parse_speed_limit, requests, set_speed_limit
__all__ = ("requests", "format_speed", "parse_speed_limit", "set_speed_limit")
__all__ = ("requests", "default_max_workers", "format_speed", "parse_speed_limit", "set_speed_limit")
+6 -1
View File
@@ -1019,6 +1019,11 @@ def build_session_spec(session: Optional[Any]) -> Optional[dict[str, Any]]:
return None
def default_max_workers() -> int:
"""Return the per-track worker count to use when the caller gives none."""
return min(16, (os.cpu_count() or 1) + 4)
def rebuild_session(spec: dict[str, Any], max_workers: int) -> Optional[Any]:
"""Reconstruct an HTTP session inside a child process from a spec built by ``build_session_spec``.
@@ -1343,7 +1348,7 @@ def requests(
urls = [urls]
if not max_workers:
max_workers = min(16, (os.cpu_count() or 1) + 4)
max_workers = default_max_workers()
# A spawned child re-imports this module and would start with no TokenBucket, so the
# configured cap would silently stop applying; the cap wins over the fan-out, matching