Skip to content

Commit d27dd4e

Browse files
mweinbachclaude
andcommitted
perf(server): skip redundant Android SDK PATH scans and idle host refreshes
Check the standard Android SDK install locations before scanning PATH, dedupe PATH entries and check existence before realPath, and only refresh device hosts when SSH host reconciliation actually adds or removes a host. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b03534f commit d27dd4e

2 files changed

Lines changed: 43 additions & 20 deletions

File tree

‎apps/server/src/device/DeviceService.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,9 @@ export const make = Effect.gen(function* () {
10871087
configured.delete(id);
10881088
removed.push({ id, scope: previous.scope });
10891089
}
1090-
yield* service.refreshHosts;
1090+
if (removed.length > 0) {
1091+
yield* service.refreshHosts;
1092+
}
10911093
return removed;
10921094
}),
10931095
);
@@ -1103,6 +1105,7 @@ export const make = Effect.gen(function* () {
11031105
);
11041106
yield* service.withLifecycleLock(
11051107
Effect.gen(function* () {
1108+
let added = false;
11061109
for (const host of next) {
11071110
if (configured.has(host.id)) continue;
11081111
const hostScope = yield* Scope.fork(scope);
@@ -1127,8 +1130,11 @@ export const make = Effect.gen(function* () {
11271130
).pipe(Effect.provideService(Scope.Scope, hostScope), Effect.provide(hostContext));
11281131
hosts.set(host.id, instance);
11291132
configured.set(host.id, { config: host, scope: hostScope });
1133+
added = true;
1134+
}
1135+
if (added) {
1136+
yield* service.refreshHosts;
11301137
}
1131-
yield* service.refreshHosts;
11321138
}),
11331139
);
11341140
});

‎apps/server/src/device/LocalDeviceHost.ts‎

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const androidSdk = Effect.gen(function* () {
132132
const platform = yield* HostProcess.Platform;
133133
const home = environment.HOME ?? environment.USERPROFILE ?? "";
134134
const explicit = environment.ANDROID_HOME?.trim() || environment.ANDROID_SDK_ROOT?.trim();
135-
const candidates = explicit
135+
const initialCandidates = explicit
136136
? [explicit]
137137
: [
138138
path.join(home, "Library", "Android", "sdk"),
@@ -143,24 +143,18 @@ const androidSdk = Effect.gen(function* () {
143143
"Sdk",
144144
),
145145
];
146-
if (!explicit) {
147-
for (const directory of (environment.PATH ?? "").split(platform === "win32" ? ";" : ":")) {
148-
if (!directory) continue;
149-
const resolved = yield* fs
150-
.realPath(path.join(directory, platform === "win32" ? "adb.exe" : "adb"))
151-
.pipe(Effect.option);
152-
if (resolved._tag === "Some") candidates.push(path.dirname(path.dirname(resolved.value)));
153-
}
154-
}
155146
const exists = (file: string) => fs.exists(file).pipe(Effect.orElseSucceed(() => false));
156-
for (const root of candidates) {
157-
const adb = yield* exists(
158-
path.join(root, "platform-tools", platform === "win32" ? "adb.exe" : "adb"),
159-
);
160-
const emulator = yield* exists(
161-
path.join(root, "emulator", platform === "win32" ? "emulator.exe" : "emulator"),
162-
);
163-
if (explicit || adb || emulator) {
147+
const inspectCandidate = (root: string) =>
148+
Effect.gen(function* () {
149+
const adb = yield* exists(
150+
path.join(root, "platform-tools", platform === "win32" ? "adb.exe" : "adb"),
151+
);
152+
const emulator = yield* exists(
153+
path.join(root, "emulator", platform === "win32" ? "emulator.exe" : "emulator"),
154+
);
155+
if (!explicit && !adb && !emulator) {
156+
return null;
157+
}
164158
const avdmanager = yield* exists(
165159
path.join(
166160
root,
@@ -176,6 +170,29 @@ const androidSdk = Effect.gen(function* () {
176170
path.join(root, "tools", "bin", platform === "win32" ? "avdmanager.bat" : "avdmanager"),
177171
));
178172
return { root, adb, emulator, avdmanager, legacyAvdmanager };
173+
});
174+
175+
for (const root of initialCandidates) {
176+
const found = yield* inspectCandidate(root);
177+
if (found) return found;
178+
}
179+
180+
if (!explicit) {
181+
const pathValue = environment.PATH ?? environment.Path ?? "";
182+
const seenDirectories = new Set<string>();
183+
const adbBinary = platform === "win32" ? "adb.exe" : "adb";
184+
for (const rawDirectory of pathValue.split(platform === "win32" ? ";" : ":")) {
185+
const directory = rawDirectory.trim();
186+
if (!directory) continue;
187+
const dirKey = platform === "win32" ? directory.toLowerCase() : directory;
188+
if (seenDirectories.has(dirKey)) continue;
189+
seenDirectories.add(dirKey);
190+
const adbCandidate = path.join(directory, adbBinary);
191+
if (!(yield* exists(adbCandidate))) continue;
192+
const resolved = yield* fs.realPath(adbCandidate).pipe(Effect.option);
193+
const root = path.dirname(path.dirname(Option.getOrElse(resolved, () => adbCandidate)));
194+
const found = yield* inspectCandidate(root);
195+
if (found) return found;
179196
}
180197
}
181198
return { root: null, adb: false, emulator: false, avdmanager: false, legacyAvdmanager: false };

0 commit comments

Comments
 (0)