From 64a2fc825905d6fc3e9e060aa85923755d3ba90e Mon Sep 17 00:00:00 2001 From: Makar Ivashko <1212makar1212@gmail.com> Date: Fri, 18 Sep 2026 15:26:09 +0300 Subject: [PATCH] perf: faster server cold start (#31630) low hanging fruits for the speedup of immich startup 1. don't wait 1s if we actually got the lock 2. move full import from the top of the file to be imported lazily in the branch --- server/src/main.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/src/main.ts b/server/src/main.ts index 72795c76d..f1027b740 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -4,7 +4,6 @@ import { ChildProcess, fork } from 'node:child_process'; import { dirname, join } from 'node:path'; import { Worker } from 'node:worker_threads'; import { PostgresError } from 'postgres'; -import { ImmichAdminModule } from 'src/app.module.js'; import { DatabaseLock, ExitCode, ImmichWorker, LogLevel, SystemMetadataKey } from 'src/enum.js'; import { ConfigRepository } from 'src/repositories/config.repository.js'; import { SystemMetadataRepository } from 'src/repositories/system-metadata.repository.js'; @@ -84,7 +83,9 @@ class Workers { return isLocked; }); - await new Promise((resolve) => setTimeout(resolve, 1000)); + if (!isLocked) { + await new Promise((resolve) => setTimeout(resolve, 1000)); + } } await kysely.destroy(); @@ -161,7 +162,7 @@ class Workers { } } -function main() { +async function main() { const immichApp = process.argv[2]; if (immichApp) { process.argv.splice(2, 1); @@ -171,6 +172,10 @@ function main() { process.title = 'immich_admin_cli'; process.env.IMMICH_LOG_LEVEL = LogLevel.Warn; + // imported lazily, so that the supervisor process does not build the whole application + // graph on every start. + const { ImmichAdminModule } = await import('./app.module.js'); + return CommandFactory.run(ImmichAdminModule); }