The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 12:15 UTC
perf(desktop): the remote editor list appears in 62 ms instead of 2.5 s (17 editors, 58 PATH entries, Windows) (#31033)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Pyseph committed
Nov 15, 2026 at 03:28 UTC
1c8143cd09f3da9de093efee50856ef0b56fc61e
2 files changed
+122
-8
apps/desktop/src/ipc/methods/window.test.ts
+107
@@ -1,6 +1,8 @@
1
import { assert, describe, it } from "@effect/vitest";
2
import * as NodeServices from "@effect/platform-node/NodeServices";
3
import type { ManagedPolicyLimits } from "@t3tools/contracts";
4
+import { EDITORS, REMOTE_CAPABLE_EDITOR_IDS } from "@t3tools/contracts";
5
+import { resolveEditorCommand } from "@t3tools/shared/editor";
6
import * as HostProcess from "@t3tools/shared/HostProcess";
7
import { ManagedPolicyFileError } from "@t3tools/shared/managedPolicyFile";
8
import * as FileSystem from "effect/FileSystem";
@@ -517,3 +519,108 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
519
assert.include(editors, "webstorm");
520
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
521
);
522
+
523
+describe("probeRemoteEditors PATH scan", () => {
524
+ const platform = HostProcess.Platform.defaultValue();
525
+ const launcherName = (command: string) => (platform === "win32" ? `${command}.cmd` : command);
526
+
527
+ const makeFakePath = Effect.fnUntraced(function* () {
528
+ const fs = yield* FileSystem.FileSystem;
529
+ const path = yield* Path.Path;
530
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-probe-path-" });
531
+ const dirs = ["a", "b", "c", "d"].map((name) => path.join(root, name));
532
+ for (const dir of dirs) yield* fs.makeDirectory(dir, { recursive: true });
533
+ // Launchers in different PATH directories, deliberately not in REMOTE_CAPABLE_EDITOR_IDS order.
534
+ for (const [dir, command] of [
535
+ [dirs[2]!, "webstorm"],
536
+ [dirs[0]!, "cursor"],
537
+ [dirs[3]!, "code"],
538
+ [dirs[1]!, "zeditor"],
539
+ ] as const) {
540
+ const file = path.join(dir, launcherName(command));
541
+ yield* fs.writeFileString(file, "#!/bin/sh\n");
542
+ if (platform !== "win32") yield* fs.chmod(file, 0o755);
543
+ }
544
+ return {
545
+ root,
546
+ env: {
547
+ HOME: root,
548
+ USERPROFILE: root,
549
+ PATH: dirs.join(platform === "win32" ? ";" : ":"),
550
+ PATHEXT: ".COM;.EXE;.BAT;.CMD",
551
+ },
552
+ };
553
+ });
554
+
555
+ const countingFileSystem = (counter: { stat: number; reads: Map<string, number> }) =>
556
+ Layer.effect(
557
+ FileSystem.FileSystem,
558
+ Effect.gen(function* () {
559
+ const fs = yield* FileSystem.FileSystem;
560
+ return FileSystem.FileSystem.of({
561
+ ...fs,
562
+ stat: (target) => {
563
+ counter.stat += 1;
564
+ return fs.stat(target);
565
+ },
566
+ readDirectory: (target, options) => {
567
+ counter.reads.set(target, (counter.reads.get(target) ?? 0) + 1);
568
+ return fs.readDirectory(target, options);
569
+ },
570
+ });
571
+ }),
572
+ ).pipe(Layer.provideMerge(NodeServices.layer));
573
+
574
+ const serialReference = (env: Record<string, string>) =>
575
+ Effect.gen(function* () {
576
+ const available: Array<string> = [];
577
+ for (const editorId of REMOTE_CAPABLE_EDITOR_IDS) {
578
+ const editor = EDITORS.find((candidate) => candidate.id === editorId);
579
+ if (editor && Option.isSome(yield* resolveEditorCommand(editor, env))) {
580
+ available.push(editorId);
581
+ }
582
+ }
583
+ return available;
584
+ });
585
+
586
+ it.effect("reads each PATH directory once instead of stat-ing every candidate per editor", () =>
587
+ Effect.gen(function* () {
588
+ const { env: baseEnv } = yield* makeFakePath();
589
+ const delimiter = platform === "win32" ? ";" : ":";
590
+ const uncachedCounter = { stat: 0, reads: new Map<string, number>() };
591
+ const cachedCounter = { stat: 0, reads: new Map<string, number>() };
592
+ const uncachedEnv = { ...baseEnv, PATH: `${baseEnv.PATH}${delimiter}${baseEnv.HOME}x1` };
593
+ const cachedEnv = { ...baseEnv, PATH: `${baseEnv.PATH}${delimiter}${baseEnv.HOME}x2` };
594
+ const uncached = yield* serialReference(uncachedEnv).pipe(
595
+ Effect.provide(countingFileSystem(uncachedCounter)),
596
+ );
597
+ const cached = yield* probeRemoteEditors
598
+ .handler(undefined)
599
+ .pipe(
600
+ Effect.provideService(HostProcess.Environment, cachedEnv),
601
+ Effect.provideService(HostProcess.Platform, platform),
602
+ Effect.provide(countingFileSystem(cachedCounter)),
603
+ );
604
+ // The host can add editors from app folders the fixture can't redirect (e.g. /Applications).
605
+ const fixtureEditors = ["cursor", "vscode", "zed", "webstorm"];
606
+ assert.deepStrictEqual(
607
+ uncached.filter((id) => fixtureEditors.includes(id)),
608
+ fixtureEditors,
609
+ );
610
+ assert.deepStrictEqual(cached, uncached);
611
+ assert.isAbove(uncachedCounter.stat, 0);
612
+ // On every platform the probe lists each PATH directory at most once. Only PATH entries count:
613
+ // resolveEditorCommand also reads app folders such as /Applications on macOS.
614
+ const pathReads = cachedEnv.PATH.split(delimiter)
615
+ .filter((entry) => entry.length > 0)
616
+ .map((entry) => cachedCounter.reads.get(entry) ?? 0);
617
+ assert.isAbove(Math.max(...pathReads), 0);
618
+ assert.isAtMost(Math.max(...pathReads), 1);
619
+ // Without the listings, Windows stats every PATH entry x PATHEXT candidate for each editor;
620
+ // elsewhere there is no PATHEXT, so the stat count is about the same either way.
621
+ if (platform === "win32") {
622
+ assert.isBelow(cachedCounter.stat, uncachedCounter.stat / 2);
623
+ }
624
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
625
+ );
626
+});
apps/desktop/src/ipc/methods/window.ts
+15
-8
@@ -17,6 +17,7 @@ import {
17
} from "@t3tools/contracts";
18
import { PROJECT_FAVICON_EXTENSIONS } from "@t3tools/shared/projectFavicon";
19
import { resolveEditorCommand } from "@t3tools/shared/editor";
20
+import { withPathDirectoryListings } from "@t3tools/shared/shell";
21
import * as HostProcess from "@t3tools/shared/HostProcess";
22
import { isRelayTracingEnabled } from "@t3tools/shared/otelEnvironment";
23
import * as FileSystem from "effect/FileSystem";
@@ -427,20 +428,26 @@ export const openSystemSettings = DesktopIpc.makeIpcMethod({
428
}),
429
});
430
431
+const REMOTE_EDITOR_PROBE_CONCURRENCY = 8;
432
+
433
export const probeRemoteEditors = DesktopIpc.makeIpcMethod({
434
channel: IpcChannels.PROBE_REMOTE_EDITORS_CHANNEL,
435
payload: Schema.Undefined,
436
result: Schema.Array(EditorId),
437
handler: Effect.fn("desktop.ipc.window.probeRemoteEditors")(function* () {
435
- const available: Array<EditorId> = [];
438
const env = yield* HostProcess.Environment;
437
- for (const editorId of REMOTE_CAPABLE_EDITOR_IDS) {
438
- const editor = EDITORS.find((editor) => editor.id === editorId);
439
- if (editor && Option.isSome(yield* resolveEditorCommand(editor, env))) {
440
- available.push(editorId);
441
- }
442
- }
443
- return available;
439
+ // Shared listings stop each editor re-stating every PATH entry x PATHEXT candidate on Windows.
440
+ const resolved = yield* Effect.forEach(
441
+ REMOTE_CAPABLE_EDITOR_IDS,
442
+ (editorId) => {
443
+ const editor = EDITORS.find((editor) => editor.id === editorId);
444
+ return editor
445
+ ? resolveEditorCommand(editor, env).pipe(Effect.map(Option.isSome))
446
+ : Effect.succeed(false);
447
+ },
448
+ { concurrency: REMOTE_EDITOR_PROBE_CONCURRENCY },
449
+ ).pipe(withPathDirectoryListings);
450
+ return REMOTE_CAPABLE_EDITOR_IDS.filter((_, index) => resolved[index]);
451
}),
452
});
453