Skip to content

Commit 07c5a53

Browse files
committed
fix(platform-apple): keep perf-target resolution lazy behind the perf facade
perf-facade.ts, perf.ts, and perf-xctrace.ts all statically imported the newly split perf-target.ts, adding it as a genuinely new eager module to the facade's closure. Load it on demand at each call site instead, the same pattern already used by simctl-facade.ts and runner-operations-facade.ts, keeping the facade's process-target path implementation-lazy.
1 parent 709524a commit 07c5a53

3 files changed

Lines changed: 29 additions & 16 deletions

File tree

‎packages/platform-apple/src/core/perf-xctrace.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ import {
3333
parseAppleTimeProfileSummary,
3434
type AppleTimeProfileFunction,
3535
} from './perf-time-profile.ts';
36-
import {
37-
readAppleProcessSamples,
38-
resolveAppleExecutable,
39-
resolveIosDevicePerfTarget,
40-
} from './perf-target.ts';
4136
import { IOS_DEVICECTL_DEFAULT_HINT, resolveIosDevicectlHint } from './devicectl.ts';
4237
import { runXcrun } from './tool-provider.ts';
4338

@@ -348,6 +343,8 @@ async function resolveAppleXctracePerfTarget(
348343
hint: 'Android native profiling belongs to the Android perf rollout and is not implemented under Apple xctrace.',
349344
});
350345
}
346+
const { readAppleProcessSamples, resolveAppleExecutable, resolveIosDevicePerfTarget } =
347+
await import('./perf-target.ts');
351348
if (isIosFamily(device) && device.kind === 'device') {
352349
const processes = await resolveIosDevicePerfTarget(device, appBundleId);
353350
return {

‎packages/platform-apple/src/core/perf.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ import {
2828
resolveXmlProcess,
2929
type XmlReference,
3030
} from './perf-xml.ts';
31-
import {
32-
readAppleProcessSamples,
33-
resolveAppleExecutable,
34-
resolveIosDevicePerfTarget,
35-
type AppleProcessSample,
36-
} from './perf-target.ts';
31+
import type { AppleProcessSample } from './perf-target.ts';
3732
import { exportAppleXctraceData, recordAppleXctraceTimedTrace } from './perf-xctrace.ts';
3833
import {
3934
APPLE_FRAME_SAMPLE_DESCRIPTION,
@@ -105,6 +100,7 @@ export async function sampleAppleMemoryPerf(
105100
return await sampleIosDeviceMemoryPerf(device, appBundleId);
106101
}
107102

103+
const { readAppleProcessSamples, resolveAppleExecutable } = await import('./perf-target.ts');
108104
const executable = await resolveAppleExecutable(device, appBundleId);
109105
const processes = await readAppleProcessSamples(device, executable);
110106
if (processes.length === 0) {
@@ -290,6 +286,7 @@ export async function sampleAppleFramePerf(
290286
);
291287
}
292288

289+
const { resolveIosDevicePerfTarget } = await import('./perf-target.ts');
293290
const processes = await resolveIosDevicePerfTarget(device, appBundleId);
294291
const capture = await captureIosDeviceFramePerf(device, appBundleId, processes);
295292
return parseAppleFramePerfSample({
@@ -484,6 +481,7 @@ async function sampleIosDeviceMemoryPerf(
484481
device: DeviceInfo,
485482
appBundleId: string,
486483
): Promise<AppleMemoryPerfSample> {
484+
const { resolveIosDevicePerfTarget } = await import('./perf-target.ts');
487485
const processes = await resolveIosDevicePerfTarget(device, appBundleId);
488486
const capture = await captureIosDevicePerfTable(device, appBundleId);
489487
const snapshot = summarizeIosDeviceMemorySnapshot(
@@ -600,6 +598,7 @@ async function resolveAppleMemorySnapshotProcess(
600598
appBundleId: string,
601599
executable: { executableName: string; executablePath?: string },
602600
): Promise<AppleProcessSample> {
601+
const { readAppleProcessSamples } = await import('./perf-target.ts');
603602
const processes = await readAppleProcessSamples(device, executable);
604603
const processInfo = processes.sort((left, right) => right.rssKb - left.rssKb)[0];
605604
if (processInfo) return processInfo;
@@ -619,6 +618,7 @@ async function resolveAppleMemorySnapshotTarget(
619618
| Extract<AppleMemorySnapshotResult, { available: false }>
620619
> {
621620
try {
621+
const { resolveAppleExecutable } = await import('./perf-target.ts');
622622
const executable = await resolveAppleExecutable(device, appBundleId);
623623
return {
624624
available: true,

‎packages/platform-apple/src/perf-facade.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,27 @@ export {
66
sampleAppleFramePerf,
77
sampleAppleMemoryPerf,
88
} from './core/perf.ts';
9-
export {
10-
readAppleProcessSamples,
11-
resolveAppleExecutable,
12-
resolveIosDevicePerfTarget,
13-
} from './core/perf-target.ts';
9+
export async function readAppleProcessSamples(
10+
...args: Parameters<(typeof import('./core/perf-target.ts'))['readAppleProcessSamples']>
11+
): ReturnType<(typeof import('./core/perf-target.ts'))['readAppleProcessSamples']> {
12+
const { readAppleProcessSamples: run } = await import('./core/perf-target.ts');
13+
return run(...args);
14+
}
15+
16+
export async function resolveAppleExecutable(
17+
...args: Parameters<(typeof import('./core/perf-target.ts'))['resolveAppleExecutable']>
18+
): ReturnType<(typeof import('./core/perf-target.ts'))['resolveAppleExecutable']> {
19+
const { resolveAppleExecutable: run } = await import('./core/perf-target.ts');
20+
return run(...args);
21+
}
22+
23+
export async function resolveIosDevicePerfTarget(
24+
...args: Parameters<(typeof import('./core/perf-target.ts'))['resolveIosDevicePerfTarget']>
25+
): ReturnType<(typeof import('./core/perf-target.ts'))['resolveIosDevicePerfTarget']> {
26+
const { resolveIosDevicePerfTarget: run } = await import('./core/perf-target.ts');
27+
return run(...args);
28+
}
29+
1430
export {
1531
cleanupAppleXctracePerfCapture,
1632
isRetryableIosDeviceTraceRecordFailure,

0 commit comments

Comments
 (0)