From b9e3985058f5bbc2de5fc3c70a53a5d7d5197c40 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 3 Apr 2025 15:24:35 -0700 Subject: [PATCH] Better preload time counting --- app/main.ts | 5 ++++- preload.wrapper.ts | 9 +++++++++ ts/test-mock/benchmarks/startup_bench.ts | 5 +++-- ts/test-mock/playwright.ts | 1 + ts/window.d.ts | 1 + ts/windows/main/phase1-ipc.ts | 10 ++++++++++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/main.ts b/app/main.ts index c04038a639..feb9d1c8fe 100644 --- a/app/main.ts +++ b/app/main.ts @@ -2125,7 +2125,8 @@ app.on('ready', async () => { // We use this event only a single time to log the startup time of the app // from when it's first ready until the loading screen disappears. ipc.once('signal-app-loaded', (event, info) => { - const { preloadTime, connectTime, processedCount } = info; + const { preloadCompileTime, preloadTime, connectTime, processedCount } = + info; const loadTime = Date.now() - startTime; const sqlInitTime = sqlInitTimeEnd - sqlInitTimeStart; @@ -2136,6 +2137,7 @@ app.on('ready', async () => { const innerLogger = getLogger(); innerLogger.info('App loaded - time:', loadTime); innerLogger.info('SQL init - time:', sqlInitTime); + innerLogger.info('Preload Compile - time:', preloadCompileTime); innerLogger.info('Preload - time:', preloadTime); innerLogger.info('WebSocket connect - time:', connectTime); innerLogger.info('Processed count:', processedCount); @@ -2146,6 +2148,7 @@ app.on('ready', async () => { event.sender.send('ci:event', 'app-loaded', { loadTime, sqlInitTime, + preloadCompileTime, preloadTime, connectTime, processedCount, diff --git a/preload.wrapper.ts b/preload.wrapper.ts index 54854af8cf..9bf47d3155 100644 --- a/preload.wrapper.ts +++ b/preload.wrapper.ts @@ -130,8 +130,17 @@ if (cachedData || process.env.GENERATE_PRELOAD_CACHE) { } // eslint-disable-next-line import/no-dynamic-require +window.preloadCompileStartTime = Date.now(); require(srcPath); +if (script) { + if (script.cachedDataRejected) { + console.log('preload cache rejected'); + } else { + console.log('preload cache hit'); + } +} + // See `ts/scripts/generate-preload-cache.ts` if (script && process.env.GENERATE_PRELOAD_CACHE) { writeFileSync(cachePath, script.createCachedData()); diff --git a/ts/test-mock/benchmarks/startup_bench.ts b/ts/test-mock/benchmarks/startup_bench.ts index 3c1aa08cce..26dbcf65c4 100644 --- a/ts/test-mock/benchmarks/startup_bench.ts +++ b/ts/test-mock/benchmarks/startup_bench.ts @@ -113,8 +113,9 @@ Bootstrap.regressionBenchmark( const [, info] = await Promise.all([queue(), run()]); - const { loadTime, preloadTime, connectTime } = info; - const messagesDuration = loadTime - preloadTime - connectTime; + const { loadTime, preloadTime, preloadCompileTime, connectTime } = info; + const messagesDuration = + loadTime - preloadTime - preloadCompileTime - connectTime; return { messagesDuration, diff --git a/ts/test-mock/playwright.ts b/ts/test-mock/playwright.ts index 6b4bbea410..5fe7727e0c 100644 --- a/ts/test-mock/playwright.ts +++ b/ts/test-mock/playwright.ts @@ -19,6 +19,7 @@ import type { SocketStatuses } from '../textsecure/SocketManager'; export type AppLoadedInfoType = Readonly<{ loadTime: number; preloadTime: number; + preloadCompileTime: number; connectTime: number; messagesPerSec: number; }>; diff --git a/ts/window.d.ts b/ts/window.d.ts index b459c0a767..db75ea5101 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -281,6 +281,7 @@ declare global { SignalContext: SignalContextType; // Used only in preload to calculate load time + preloadCompileStartTime: number; preloadStartTime: number; preloadEndTime: number; diff --git a/ts/windows/main/phase1-ipc.ts b/ts/windows/main/phase1-ipc.ts index 3900fed0af..32c625c3b5 100644 --- a/ts/windows/main/phase1-ipc.ts +++ b/ts/windows/main/phase1-ipc.ts @@ -95,6 +95,16 @@ const IPC: IPCType = { ipc.invoke('settings:get:mediaCameraPermissions'), logAppLoadedEvent: ({ processedCount }) => ipc.send('signal-app-loaded', { + // Sequence of events: + // 1. Preload compile start + // 2. Preload start + // 3. Preload end + // + // Compile time is thus: start - compileStart + preloadCompileTime: + window.preloadStartTime - window.preloadCompileStartTime, + + // Preload time is: end - start preloadTime: window.preloadEndTime - window.preloadStartTime, connectTime: preloadConnectTime - window.preloadEndTime, processedCount,