perf(mobile): show the cached thread list sooner and stop the freeze after it #16713
Mergedjuliusmarmingemerged 5 commits into
main fromrefs/pull/16713/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
juliusmarminge changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/mobile/src/connection/shell-cache-encoding.ts line 120OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -62,0 +100,21 @@100+ const parsed = yield* decodeJson(raw);101+ const rawLinks = detachPullRequests(parsed);102+ const stored = yield* decodeStoredShell(parsed);103+ const threadIds = stored.snapshot.threads.map((thread) => thread.id);104+ const loadPullRequests = yieldToHost.pipe(105+ // Schema decoding runs when called, so build the decode only after the yield.106+ Effect.andThen(Effect.suspend(() => decodePullRequestLinks(rawLinks))),107+ Effect.map(108+ (links) =>109+ new Map(110+ threadIds.flatMap((threadId, index) => {111+ const threadLinks = links[index];112+ return threadLinks === undefined ? [] : [[threadId, threadLinks] as const];113+ }),114+ ),115+ ),116+ // The rows stay usable without links; the next server snapshot replaces them.117+ Effect.catch((cause) =>118+ Effect.logWarning("Discarding unreadable cached pull request links.", {119+ environmentId: stored.environmentId,120+ cause: String(cause),
juliusmarminge changed the title
- packages/client-runtime/src/state/shell.ts line 338OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -258,4 +329,10 @@258329 );259330 const httpSnapshot = yield* snapshotLoader.load(prepared);260331 if (Option.isSome(httpSnapshot)) {261- yield* applyItems([{ kind: "snapshot", snapshot: httpSnapshot.value }]);332+ if (cachedFill !== undefined) yield* Fiber.interrupt(cachedFill);333+ const previous = yield* SubscriptionRef.get(state);334+ const snapshot = reuseUnchangedThreadShells(335+ Option.getOrNull(previous.snapshot),336+ withoutDeferredPullRequests(httpSnapshot.value),337+ );338+ yield* applyItems([{ kind: "snapshot", snapshot }]);
- packages/client-runtime/src/state/shellPullRequests.ts lines 70 to 79OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +59,21 @@59+ const linksByThreadId = new Map<ThreadId, ReadonlyArray<ThreadPullRequestLink>>();60+ let batchSize = LINKS_PER_BATCH;61+ for (const [index, threadId] of threadIds.entries()) {62+ const raw = rawLinks[index];63+ if (raw === undefined) continue;64+ const size = Array.isArray(raw) ? raw.length : 1;65+ if (batchSize + size > LINKS_PER_BATCH) {66+ yield* yieldToHost;67+ batchSize = 0;68+ }69+ batchSize += size;70+ const links = yield* decodeThreadLinks(raw);71+ if (links !== undefined) linksByThreadId.set(threadId, links);72+ }73+ return linksByThreadId as ReadonlyMap<ThreadId, ReadonlyArray<ThreadPullRequestLink>>;74+ }).pipe(75+ Effect.catch((cause) =>76+ Effect.logWarning("Discarding unreadable shell pull request links.", {77+ cause: String(cause),78+ }).pipe(Effect.as(new Map<ThreadId, ReadonlyArray<ThreadPullRequestLink>>())),79+ ),
- @@ -0,0 +56,21 @@56+ const threadIds = snapshot.threads.map((thread) => thread.id);57+ // Schema decoding runs when called, so each thread's decode is built after a yield.58+ const loadPullRequests = Effect.gen(function* () {59+ const linksByThreadId = new Map<ThreadId, ReadonlyArray<ThreadPullRequestLink>>();60+ let batchSize = LINKS_PER_BATCH;61+ for (const [index, threadId] of threadIds.entries()) {62+ const raw = rawLinks[index];63+ if (raw === undefined) continue;64+ const size = Array.isArray(raw) ? raw.length : 1;65+ if (batchSize + size > LINKS_PER_BATCH) {66+ yield* yieldToHost;67+ batchSize = 0;68+ }69+ batchSize += size;70+ // An unreadable thread keeps no links; the others still fill in.71+ const links = yield* decodeThreadLinks(raw).pipe(72+ Effect.catch((cause) =>73+ Effect.logWarning("Discarding unreadable shell pull request links.", {74+ threadId,75+ cause: String(cause),76+ }).pipe(Effect.as(undefined)),
juliusmarminge merged thisf9e16b3
juliusmarminge closed this
Sign in to join this conversation.

macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed