fix: make source maps opt-in to restore v1.67.0 memory baseline

Production source maps (--enable-source-maps) caused a ~50% memory increase
(600MB to 1000MB) in v1.68.0. Node.js loads all .map files into memory when
this flag is enabled, and Next.js server chunks generate hundreds of map files.

Changes:
- Guard productionBrowserSourceMaps and serverSourceMaps behind
  HOMARR_ENABLE_SOURCE_MAPS env var (default off)
- Guard .map copy step and NODE_OPTIONS in Dockerfile behind
  ENABLE_SOURCE_MAPS build arg (default false)
- run.sh checks HOMARR_ENABLE_SOURCE_MAPS before setting --enable-source-maps
- Add Docker-based memory regression CI job (<700MB threshold)

Closes #6123
This commit is contained in:
ajnart committed 2026-06-29 10:08:52 +02:00
1 parent 597b5fbc8d
commit 57ef0af4a2
4 files changed
+78 -17

No files matched your search

+15 -13
View File
@@ -20,16 +20,18 @@ ARG DISABLE_REDIS_LOGS='true'
RUN corepack enable pnpm && pnpm build
# The standalone output tracing omits server chunk source maps (.next/server/**/*.map), which is
# where production Node stack frames point. Copy the .map files into the standalone tree (preserving
# directory structure) so the existing standalone COPY ships them, keeping traces readable.
# See https://github.com/homarr-labs/homarr/issues/5891
RUN cd apps/nextjs/.next/server && \
find . -name '*.map' | while IFS= read -r map; do \
dest="../standalone/apps/nextjs/.next/server/$map"; \
mkdir -p "$(dirname "$dest")"; \
cp "$map" "$dest"; \
done
# Copy server chunk source maps into standalone output when enabled.
# Off by default to avoid the significant memory overhead of --enable-source-maps in Node.js.
# See https://github.com/homarr-labs/homarr/issues/6123 and https://github.com/nodejs/node/issues/46140
ARG ENABLE_SOURCE_MAPS=false
RUN if [ "$ENABLE_SOURCE_MAPS" = "true" ]; then \
cd apps/nextjs/.next/server && \
find . -name '*.map' | while IFS= read -r map; do \
dest="../standalone/apps/nextjs/.next/server/$map"; \
mkdir -p "$(dirname "$dest")"; \
cp "$map" "$dest"; \
done; \
fi
FROM base AS runner
WORKDIR /app
@@ -75,9 +77,9 @@ ENV DB_DRIVER='better-sqlite3'
ENV AUTH_PROVIDERS='credentials'
ENV REDIS_IS_EXTERNAL='false'
ENV NODE_ENV='production'
# Tell Node to symbolicate stack traces using the shipped .map files so production logs
# show original source locations instead of minified frames, see https://github.com/homarr-labs/homarr/issues/5891
ENV NODE_OPTIONS='--enable-source-maps'
# Pass through the source maps toggle so run.sh can conditionally set NODE_OPTIONS.
ARG ENABLE_SOURCE_MAPS=false
ENV HOMARR_ENABLE_SOURCE_MAPS=$ENABLE_SOURCE_MAPS
ENTRYPOINT [ "/app/entrypoint.sh" ]
CMD ["sh", "run.sh"]