Cut background polling CPU churn with read caches and fetch backoff#648
Merged
Conversation
Log audit showed ~8,200 subprocess spawns and 6,400 full tasks.json re-parses per hour driven by background pollers. Four targeted fixes: - data.ts: mtime/size stat-validated cache for loadProjects/loadTasks; cache hits return shallow copies, mutators bypass, saves invalidate - git.ts fetchOrigin: exponential backoff (2min..30min) for failing fetches — cooldown was previously only set on success, so repos with a dead remote were re-fetched on every poller tick forever - git.ts detectDefaultCompareRef: 10min TTL cache (runs git shortlog over two weeks of history, was invoked by every getResolvedProject) - github.ts: cache gh auth status (60s, authenticated only) and gh auth token (5min) instead of 3 subprocesses per GitHub call See decisions/067-background-polling-read-caches.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A one-hour log audit showed ~8,200 subprocess spawns/hour and ~6,400 full re-parses of
tasks.json(1.4 MB) driven by background pollers. This PR adds four independent, targeted caches:data.ts— mtime/size stat-validated read cache forloadProjects()/loadTasks(). Cache hits return shallow copies, mutator paths bypass the cache, saves invalidate it. Cross-process safe: validation is a per-readstat(), so external writes are always picked up.git.tsfetchOrigin— exponential backoff for failing fetches (2 min base, doubling to a 30 min cap) perprojectPath:branch. Previously the cooldown was only set on success, so repos with an unreachable remote were re-fetched on every poller tick forever (one repo logged 213 failed fetches/hour).git.tsdetectDefaultCompareRef— 10 min TTL promise cache. It runsgit shortlogover two weeks of history and was invoked by everygetResolvedProjectRPC (renderer polls every 10 s → 260 shortlogs/hour).github.ts—gh auth statuscached for 60 s (only theauthenticatedresult, so a freshgh auth loginis visible immediately) andgh auth tokencached for 5 min, instead of spawning three subprocesses per GitHub call.Details and trade-offs in
decisions/067-background-polling-read-caches.md.This PR was authored by Claude (the AI assistant working on this branch).