perf: desktop and server start without shell and fork waits, and thread views stay mounted #18219
Closedmaria-rckswants to merge 250+ commits into
t3/app-startup-performance-audit fromt3/perf-wave2opened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
juliusmarminge added labelsmacroscope-review
- apps/server/src/serviceDatabaseBackup.ts lines 27 to 29OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +9,21 @@9+ source = new NodeSqlite.DatabaseSync(databasePath, { readOnly: true });10+ source.exec("PRAGMA busy_timeout = 5000; BEGIN");11+ source.prepare("SELECT name FROM sqlite_schema LIMIT 1").get();12+ if (source.prepare("PRAGMA journal_mode").get()?.journal_mode === "wal") return source;13+ } catch {14+ // Fall back to the stopped copy.15+ }16+ source?.close();17+ return undefined;18+}19+20+/**21+ * Pin WAL frames with a read transaction until shutdown, then overlay the final22+ * WAL on the online snapshot so rollback keeps writes made during the copy.23+ */24+export async function prepareServiceDatabaseBackup(databasePath: string, stagingDir: string) {25+ const source = openWalReader(databasePath);26+ if (source === undefined) return undefined;27+ await NodeFSP.rm(stagingDir, { recursive: true, force: true });28+ await NodeFSP.mkdir(stagingDir, { recursive: true, mode: 0o700 });29+ try {apps/web/src/components/ThreadTerminalDrawer.tsx lines 626 to 626Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -586,3 +596,14 @@586596 useEffect(() => {587597 const mount = containerRef.current;588598 if (!mount) return;599+ const surfaceKey = [environmentId, threadId, terminalId, cwd, worktreePath, runtimeEnvKey].join(600+ "\u0000",601+ );602+ const parked = parkedSurfaceRef.current;603+ if (parked !== null) {604+ parkedSurfaceRef.current = null;605+ parked.cancelRelease();606+ // Shown again for the same session: the surface was kept as it was.607+ if (parked.key === surfaceKey) return parked.cleanup;608+ parked.release();609+ }
- apps/web/src/components/chat/McpAppFrame.tsx lines 237 to 239Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -251,3 +252,19 @@251252 cancelled = true;252253 };253254 }, [props.environmentId, props.threadId, props.itemId, app.tool]);255+ // Activity preserves iframe DOM; stop hidden apps and reinitialize on reveal.256+ const [parked, setParked] = useState(false);257+ useEffect(() => {258+ if (parked) {259+ minting.current = false;260+ // oxlint-disable-next-line react/set-state-in-effect -- A kept view shown again loads a new document.261+ setSrc(null);262+ setNavigatedAway(false);263+ setDisplayMode("inline");264+ setDocumentGeneration((value) => value + 1);265+ setParked(false);266+ return;267+ }268+ const box = boxRef.current;269+ return () => {270+ if (!box?.isConnected) return;
- apps/server/src/process/spawnHostProcess.ts line 90Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +70,21 @@70+ try {71+ child = NodeChildProcess.spawn(request.command, [...request.args], request.options);72+ } catch (cause) {73+ send({ type: "error", id, error: toSpawnHostError(cause) });74+ return;75+ }76+ // Stop reads before the loop polls, preserving every byte for the server.77+ const stdio = child.stdio.map((socket) => {78+ if (socket) stopReading(socket as NodeNet.Socket);79+ return socket as NodeNet.Socket | null;80+ });81+ // ChildProcess destroys stdin on exit, which can come before its socket leaves the send queue.82+ child.stdin = null;83+ child.on("error", (cause) => send({ type: "error", id, error: toSpawnHostError(cause) }));84+ child.once("spawn", () => {85+ stdio.forEach((socket, fd) => {86+ if (socket) send({ type: "stdio", id, fd }, socket);87+ });88+ send({ type: "spawn", id, pid: child.pid! });89+ });90+ child.on("exit", (code, signal) => send({ type: "exit", id, code, signal }));apps/web/src/components/ChatView.tsx line 6113OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -5932,4 +6107,7 @@59326107 },59336108 });593461095935- // A focused desktop browser page forwards these chords as menu actions.6110+ // Text typed on the way to this view, while the view the user left was still shown.6111+ useEffect(() => {6112+ const text = takeHeldText(viewRouteTargetKey);6113+ if (text !== null) composerRef.current?.insertTextAtEnd(text);apps/web/src/connection/platform.ts line 624Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -565,3 +577,14 @@565577 registrations: Stream.empty,566578 });567579 }580+ const cachedTarget = yield* Effect.try(() => localStorage.getItem(PRIMARY_TARGET_KEY)).pipe(581+ Effect.flatMap(Schema.decodeUnknownEffect(PrimaryTargetJson)),582+ Effect.option,583+ );584+ const primary = readPrimaryEnvironmentTargetResult();585+ const cachedRegistrations =586+ Option.isSome(cachedTarget) &&587+ primary._tag === "Success" &&588+ cachedTarget.value.httpBaseUrl === primary.target?.target.httpBaseUrl &&589+ cachedTarget.value.wsBaseUrl === primary.target.target.wsBaseUrl590+ ? [new PrimaryConnectionRegistration({ target: cachedTarget.value })]
juliusmarminge assignedjuliusmarminge
- apps/server/src/ws.ts lines 1717 to 1718Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1691,10 +1705,14 @@16911705 ),16921706 );169317071694- const loadServerConfig = (options: { readonly usageLimitsCommand: boolean }) =>1708+ const loadServerConfig = (options: {1709+ readonly usageLimitsCommand: boolean;1710+ readonly deferEditors?: boolean;1711+ readonly deferCatalogs?: boolean;1712+ }) =>16951713 Effect.gen(function* () {16961714 const keybindingsConfig = yield* keybindings.loadConfigState;16971715 const currentProviders = yield* providerRegistry.getProviders;1698- const providers = options.usageLimitsCommand1716+ const completeProviders = options.usageLimitsCommand16991717 ? withUsageLimitsCommands(currentProviders, yield* usageLimitSources.current)17001718 : currentProviders;
maria-rcks closed this
Sign in to join this conversation.
Macroscope has since reviewed this pull request. An earlier review was skipped by a cost limit; a review has now completed, so that notice no longer applies.