Skip to content

perf(daily): parallelize week-window fetch + stop refresh firing at board-open - #914

Merged
wei18 merged 1 commit into
mainfrom
perf/912-daily-fetch-parallel-teardown
Jul 20, 2026
Merged

wei18 merged 1 commit into
mainfrom
perf/912-daily-fetch-parallel-teardown

Conversation

@wei18

@wei18 wei18 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

What

Two Daily-hub performance fixes (owner-reported: enable window too long + fetch too frequent).

  1. Parallelize the week-window fetch — the 7-day CloudKit fetch was a serial for-loop (MS: 8, window→failed sequential). Now a withThrowingTaskGroup fan-out, results re-sorted by offsetFromToday to preserve week-strip order; MS runs bestTimes/window/failed as 3 concurrent async let lanes.
  2. Stop refresh() firing at board-open — sessionTeardownCount over-fired because GameBoardRedirect's synthetic path-pop at OPEN shrank path like a close. New handlePathShrink guards !isGamePresented; GameBoardRedirect now presents before popping, so the open-time shrink is filtered.

Why

The enable window was bound by 7 serial CK round-trips; the fetch re-ran on every teardown bump, and the counter double-counted board-open as a session-end. Both facets share one root: full uncached re-fetch triggered too liberally.

Verification

  • Concurrency tests: gated fakes assert callCount reaches 7 (MS 8) before unlock — deadlocks on the old serial loop — plus week-strip order [6..0].
  • Open-vs-close: 3 tests assert no teardown bump at open, bump at close; traced on both iOS (onPresentBoard wired) and macOS (nil → every shrink still bumps, close via separate dismissGame).
  • swift test GameAppKit / SudokuKit Daily / MinesweeperKit all green; swiftlint --strict clean.
  • Dual CR: APPROVE-with-cosmetic ×2 (stale doc corrected; MS-only failed-ids lane is an inherent app difference, not drift).

Scoped out (flagged for a follow-up issue): MS's fetchCompletedDailyIds issues 7 identical CK queries (no date predicate, client-side filtered) — parallelized here but the query-dedup is a deeper caching change. Client-side caching of immutable older days also deferred.

Closes #912

🤖 Generated with Claude Code

…oard-open

The Daily hub's enable window dragged and it re-fetched too often.

(a) Enable latency: fetchWeekWindow issued 7 CloudKit round-trips in a
serial for-loop (MS: 8, window→failed sequential). Both now fan out via
withThrowingTaskGroup; results re-sorted by offsetFromToday so the week
strip order is preserved, and MS runs bestTimes/window/failed as three
concurrent async-let lanes. WeekWindowSlot is Sendable; persistence is
captured as a local let before the group (actors serialize at the mailbox,
no deadlock); degrade-on-failure semantics unchanged.

(b) Over-frequent fetch: .onChange(of: sessionTeardownCount) re-ran the
full fetch, and the counter over-fired — GameBoardRedirect's synthetic
path-pop at board OPEN shrank path exactly like a close. GameBoardRedirect
now calls onPresent (→ isGamePresented=true) before popping, and the new
GameRootViewModel.handlePathShrink guards !isGamePresented so the open-time
shrink is filtered — refresh() no longer fires at board open. macOS
(onPresentBoard nil) is unaffected: isGamePresented stays false so every
path-shrink still bumps as before; genuine iOS close goes through the
separate dismissGame() path, untouched.

Tests: gated-fake concurrency tests assert callCount reaches 7 (MS 8)
before unlock (deadlocks on the old serial loop) + week-strip order
[6..0]; 3 open-vs-close tests assert no bump at open, bump at close.
Sudoku's GatedWeekWindowPersistence fake converted single-continuation →
queue (parity with MS's #886 GatedQueryGateway) to hold 7 concurrent
in-flight calls. Dual CR: APPROVE-with-cosmetic x2 (stale gameSessionDidTearDown
doc corrected here; MS-only failed-ids lane is an inherent app difference).

Closes #912

Co-Authored-By: Claude Fable 5 <[email protected]>
@wei18
wei18 enabled auto-merge (squash) July 20, 2026 09:11
@wei18
wei18 merged commit 9527fb6 into main Jul 20, 2026
5 checks passed
@wei18
wei18 deleted the perf/912-daily-fetch-parallel-teardown branch July 20, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(daily): hub enable window too long + over-frequent full re-fetch on every teardown bump

1 participant