From 8594cc884f6115094c1dba6409432e00614a6805 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Mon, 10 Aug 2026 08:49:02 +0200 Subject: [PATCH] perf(docker): stop loading the gRPC stack dockerode only needs for image builds dockerode/lib/docker.js required './session' at module scope, which pulls in @grpc/grpc-js and @grpc/proto-loader - 112 files. Its single call site is inside Docker.prototype.buildImage, the BuildKit path. Homarr lists, starts and stops containers and never builds images, so every install with a Docker widget paid for a gRPC stack it cannot reach. Measured with a forced GC, in context rather than in a bare process: requiring dockerode goes from +26.6 MiB RSS / 5.2 MiB heap to +20.6 MiB / 2.7 MiB, with grpc and protobufjs files going 63 and 49 to zero. The bare-process figure was +24.1 MiB, and quoting that would have overstated the win by 4x - most of it overlaps with what dockerode loads anyway. The patch comment records the in-context number. --- patches/dockerode@5.0.1.patch | 25 +++++++++++++++++++++++++ pnpm-lock.yaml | 7 ++++--- pnpm-workspace.yaml | 1 + 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 patches/dockerode@5.0.1.patch diff --git a/patches/dockerode@5.0.1.patch b/patches/dockerode@5.0.1.patch new file mode 100644 index 000000000..353b63fe6 --- /dev/null +++ b/patches/dockerode@5.0.1.patch @@ -0,0 +1,25 @@ +diff --git a/lib/docker.js b/lib/docker.js +index 4951f8db867b1b12b75af79be2ebae6165534960..b333e65e99a9ef420826c0b1a908d4923dffc2f6 100644 +--- a/lib/docker.js ++++ b/lib/docker.js +@@ -12,7 +12,6 @@ var EventEmitter = require('events').EventEmitter, + Node = require('./node'), + Exec = require('./exec'), + util = require('./util'), +- withSession = require('./session'), + extend = util.extend; + + var Docker = function(opts) { +@@ -301,6 +300,12 @@ Docker.prototype.buildImage = function(file, opts, callback) { + + function dialWithSession(callback) { + if (opts?.version === "2") { ++ // Loaded here rather than at module scope: './session' pulls in @grpc/grpc-js and ++ // @grpc/proto-loader (112 files), which cost +6.0 MiB RSS on top of dockerode itself. ++ // Only the BuildKit image-build path reaches this branch, so listing or starting ++ // containers paid for a gRPC stack it never used. require() is cached, so builds behave ++ // exactly as before. ++ var withSession = require('./session'); + withSession(self, optsf.authconfig,(err, sessionId, done) => { + if (err) { + return callback(err); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f863cb9be..c8b8e46ee 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -586,6 +586,7 @@ overrides: patchedDependencies: '@types/node-unifi': 5e6ae51e2a17a7f9729bfa30b0eb3d0842a5810ac6db47603ab4a6efa1ed84c5 docker-modem@5.0.7: 4a1c50dc8b726af921a34a77c4942a768bed229123ab116baa06c4e62ad6815c + dockerode@5.0.1: 0f6e47505aa4a9aa6fabe6a42b070ca984c787d197bcac3aa6367961f2f7eac3 trpc-to-openapi: 2ca3c16af0fcca0c736697ad4fe553a14f794524fa9ce0d5c3e8ee4aea76090c importers: @@ -1781,7 +1782,7 @@ importers: version: link:../core dockerode: specifier: 'catalog:' - version: 5.0.1(supports-color@10.2.2) + version: 5.0.1(patch_hash=0f6e47505aa4a9aa6fabe6a42b070ca984c787d197bcac3aa6367961f2f7eac3)(supports-color@10.2.2) devDependencies: '@homarr/tsconfig': specifier: workspace:^0.1.0 @@ -23656,7 +23657,7 @@ snapshots: transitivePeerDependencies: - supports-color - dockerode@5.0.1(supports-color@10.2.2): + dockerode@5.0.1(patch_hash=0f6e47505aa4a9aa6fabe6a42b070ca984c787d197bcac3aa6367961f2f7eac3)(supports-color@10.2.2): dependencies: '@balena/dockerignore': 1.0.2 '@grpc/grpc-js': 1.12.5 @@ -29219,7 +29220,7 @@ snapshots: byline: 5.0.0 debug: 4.4.3(supports-color@10.2.2) docker-compose: 1.4.2 - dockerode: 5.0.1(supports-color@10.2.2) + dockerode: 5.0.1(patch_hash=0f6e47505aa4a9aa6fabe6a42b070ca984c787d197bcac3aa6367961f2f7eac3)(supports-color@10.2.2) get-port: 5.1.1 proper-lockfile: 4.1.2 properties-reader: 3.0.1(supports-color@10.2.2) diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 44cf3977a..995b68e33 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -234,6 +234,7 @@ overrides: patchedDependencies: "@types/node-unifi": "patches/@types__node-unifi.patch" docker-modem@5.0.7: patches/docker-modem@5.0.7.patch + dockerode@5.0.1: patches/dockerode@5.0.1.patch "trpc-to-openapi": "patches/trpc-to-openapi.patch" allowUnusedPatches: true