Skip to content

perf(mobile): coalesce duplicate concurrent home-screen requests - #9888

Merged
nwparker merged 2 commits into
mainfrom
nwparker/perf-mobile-home-single-flight
Jul 22, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/perf-mobile-home-single-flight

Conversation

@nwparker

@nwparker nwparker commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

What

On the mobile home screen (mobile/app/index.tsx), the focus effect and the connected-state wiring independently launch overlapping one-shot requests — stats.summary, worktree.ps, accounts.list, settings.get, preflight.check, linear.status — so a cold connect + focus could fire the same batch twice, including the heavy worktree.ps.

Fix: route those one-shots through a new sendSingleFlightRequest(client, hostId, requestKind, params?) helper that coalesces concurrent identical requests into one shared promise (keyed by client identity + host + request kind), evicting the entry when it settles. Triggers, reconciliation, subscriptions, and error handling are unchanged — only genuine concurrent duplicates are collapsed.

ELI5

When you opened the app's home screen while it was connecting, it sometimes asked the computer the same few questions twice at once. Now duplicate simultaneous questions share a single answer.

Proof of zero regression

  • The helper returns the exact same promise to concurrent callers and evicts on settle (with an identity guard so a newer request isn't evicted by an older one's completion); failures propagate to every waiter (each can retry); a synchronous sendRequest throw becomes a rejected promise. Different clients/hosts/kinds never share.
  • One fresh request per trigger is preserved — only exact concurrency is shared, so no staleness.
  • mobile/app/h/[hostId]/index.tsx has zero diff (kept separate from perf(mobile): gate host polling on foreground/background #9857).
  • Verified in a deps-installed checkout: request-single-flight.test.ts (concurrent sharing, eviction after success, shared-failure propagation + retry, client/host/kind isolation), full mobile suite green, typecheck / oxlint (within max-lines) / oxfmt --check clean.

Proof of perf improvement

Removes duplicate concurrent one-shots on cold-connect/focus — most importantly a second worktree.ps (a full multi-repo process scan) and a second accounts.list/stats.summary — cutting redundant host CPU + relay/cellular bytes + a radio burst, larger over SSH/relay or with many worktrees.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds sendSingleFlightRequest to coalesce in-flight RPC reads by client, host, and request kind, with trailing follow-ups, cleanup, retry handling, and tests. Updates mobile stats, worktree, accounts, and task-provider requests to use the utility, and passes hostId through stats fetch call sites.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change and testing, but it does not follow the required template sections like Summary, Screenshots, AI Review Report, Security Audit, and Notes. Rewrite the PR description using the repository template and fill in Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: coalescing duplicate concurrent mobile home-screen requests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker force-pushed the nwparker/perf-mobile-home-single-flight branch from 2e00e2e to 5d2a6c8 Compare July 22, 2026 06:53
nwparker and others added 2 commits July 22, 2026 15:50
…ght read

Single-flight returned the in-flight promise to any trigger that arrived mid-read,
so a distinct refresh requested while a slow read was on the wire was silently
answered by the older response and never re-read the latest state (UI could stay
one refresh cycle stale). Coalesce mid-flight triggers into exactly one trailing
follow-up (latest params win) whose fresh result is delivered to those callers.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker force-pushed the nwparker/perf-mobile-home-single-flight branch from 5d2a6c8 to 233380c Compare July 22, 2026 22:54

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
mobile/src/transport/request-single-flight.test.ts (1)

27-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the remaining single-flight state transitions.

Add cases proving latest params reach the trailing request, a trigger during that trailing request queues exactly one more read, and synchronous sendRequest throws reject cleanly. These are core advertised behaviors but are not asserted here.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6444d34f-5add-4452-b100-ea6b61225f3f

📥 Commits

Reviewing files that changed from the base of the PR and between 0d82cc3 and 233380c.

📒 Files selected for processing (3)
  • mobile/app/index.tsx
  • mobile/src/transport/request-single-flight.test.ts
  • mobile/src/transport/request-single-flight.ts

@nwparker
nwparker merged commit 6a43f99 into main Jul 22, 2026
2 checks passed
@nwparker
nwparker deleted the nwparker/perf-mobile-home-single-flight branch July 22, 2026 23:22
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…blyai#9888)

* perf(mobile): coalesce overlapping home requests

Co-authored-by: Orca <[email protected]>

* fix(mobile): queue a trailing follow-up for triggers during an in-flight read

Single-flight returned the in-flight promise to any trigger that arrived mid-read,
so a distinct refresh requested while a slow read was on the wire was silently
answered by the older response and never re-read the latest state (UI could stay
one refresh cycle stale). Coalesce mid-flight triggers into exactly one trailing
follow-up (latest params win) whose fresh result is delivered to those callers.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
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.

1 participant