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.
This commit is contained in:
Thomas Camlong committed 2026-08-10 08:49:02 +02:00
1 parent 1de51a9afd
commit 8594cc884f
3 files changed
+30 -3

No files matched your search

+25
View File
@@ -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);
+4 -3
View File
@@ -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)
+1
View File
@@ -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