tv-anarchy/Sources/TVAnarchyCore/Library
Natalie ee3da4e101 perf(watch-history): stop the background poll freezing the main thread
The 8s watch-history poll ran refresh() on the main actor, which read and
JSON-decoded the unioned watch log THREE times (playedPaths, resumePositions,
episodeProgress each re-read) and called MediaPaths.toRemote() per event — and
every toRemote rebuilt ProcessInfo.environment (~22µs each, the whole env dict
is reconstructed on every access) plus a homeDirectory lookup. A live sample
caught the main thread 100% in this path; the app sat at 78–113% CPU.

- Cache MediaPaths.remoteRoot / mappings (process-constant) → kills the
  per-call env-dictionary rebuild storm.
- WatchHistory.derivedState(): read+decode the log ONCE, feed all three
  derived computations → 3× fewer reads/decodes per refresh.
- WatchHistoryController.refreshAsync(): the background poll now parses off the
  main thread on a utility task and only assigns the small results on main.

Settled CPU drops from ~78% sustained to ~0% idle.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-30 01:44:06 -04:00
..
BlackWatchlog.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
DownloadsIndex.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
FranchiseStore.swift refactor(tv-anarchy): rename PlumTV→TVAnarchy and land session work 2026-06-08 22:04:22 -07:00
IndexedFoldersStore.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
LibraryConfig.swift feat(@applications): add adult content browsing tab 2026-06-09 19:51:12 -07:00
LibraryController.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
LibraryDisplayNames.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
LibraryIndex.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
LibraryModels.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
LibraryScanner.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
LibraryStore.swift refactor(tv-anarchy): rename PlumTV→TVAnarchy and land session work 2026-06-08 22:04:22 -07:00
LocalLLMGrouper.swift feat(library): show grouping, local-LLM grouper, content IDs, watch state + registry ingest 2026-06-09 05:50:01 -07:00
PreviewService.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
RegistryIngest.swift feat(library): show grouping, local-LLM grouper, content IDs, watch state + registry ingest 2026-06-09 05:50:01 -07:00
SettingsStore.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
ShowGrouping.swift feat(library): show grouping, local-LLM grouper, content IDs, watch state + registry ingest 2026-06-09 05:50:01 -07:00
TitleLibrary.swift feat(offline): inline star-to-keep and trash-to-cull on cache rows 2026-06-30 00:12:41 -04:00
WatchHistory.swift perf(watch-history): stop the background poll freezing the main thread 2026-06-30 01:44:06 -04:00