Skip to content

[APPS] Minify backend bundles - #540

Open
ksun154 wants to merge 1 commit into
masterfrom
kelly.sun/apps-backend-minify
Open

ksun154 wants to merge 1 commit into
masterfrom
kelly.sun/apps-backend-minify

Conversation

@ksun154

@ksun154 ksun154 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What and why?

Follow-up to the pitchGPT HTTP 413 ("bundle exceeds the maximum decompressed size of 52 MB"). The server's limit is maxBundleSize = 50 * 1024 * 1024 (50 MiB) in app-builder-code's internal/uploader/bundle_storage.go; "52 MB" is that value printed in decimal units by humanize.Bytes. It complements #538, which enables tree-shaking. The two are independent and can merge in either order.

  • Production backend bundles are now minified with esbuild, using keepNames: true. Minification is always on; there's no public option.
  • Every package build logs its file count, compressed size and decompressed size. Today a 413 is the first anyone hears about bundle size; the log line makes the number visible on every build.

This takes the minification and the size reporting from #533. It leaves out #533's apps.backend.minify opt-out and its near-limit warning: the warning would hardcode a client-side copy of the server's limit, which drifts (#533's 52 MB was already the server's 50 MiB maxBundleSize printed in decimal units).

How?

  • vite/build-backend-functions.ts: sets minify: 'esbuild' and esbuild: { keepNames: true } only in the production vite.build() call. The shared getBaseBackendBuildConfig is unchanged, so the dev-server bundles sent to preview-async stay unminified.
  • archive.ts: Archive gains decompressedSize, the sum of the packaged files' sizes. The server's 50 MiB limit counts this total (frontend/, backend/*.js and manifest.json), not the zip size.
  • vite/build-package.ts: logs App package size: N files, X MB compressed, Y MB decompressed.

Measurements

Total backend JS on master's config (no tree-shaking), minification toggled:

minify: false This PR
Synthetic app: 13 functions in 3 files (zod, lodash-es, date-fns, yaml, apps-backend) 15.86 MB 3.18 MB (−80%)

Combined with #538's tree-shaking, measured on the same app (minify with keepNames, against tree-shaking alone):

Tree-shake only + minify keepNames + minify, no keepNames
Repo fixture (apps_backend_project, 7 functions) 71,271 B 42,111 B (−41%) 39,916 B
Synthetic app 4.44 MB 1.74 MB (−61%) 1.65 MB

The synthetic app is not pitchGPT. Code-heavy dependencies minify well; data- or string-heavy ones (locale tables, JSON) much less. pitchGPT has not been measured yet.

Follow-ups

  • Confirm whether Terrapin or function logs can apply source maps, which nobody has confirmed yet, and where the maps would be stored.
  • a near-limit warning, ideally in @datadog/apps-cli with the limit read from the API instead of hardcoded. The CLI would also cover uploading an existing zip, which the plugin never sees.

@ksun154 ksun154 changed the title [APPS] Minify production backend bundles with keepNames, warn near de… [APPS] Minify backend bundles and warn near the 52 MB limit Oct 1, 2026
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Tests

✅ All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 63bb070 | Docs | View more details | Give us feedback!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The behavior is well-scoped and covered by targeted tests, with only minor non-blocking convention feedback.

Review effort: Balanced
Findings: 2 Low severity

Open (2)
What changed in this PR

Minifies production backend bundles while adding archive-size reporting and warnings near the upload limit.

Changes:

  • Enables esbuild minification while preserving function and class names.
  • Tracks and logs compressed/decompressed package sizes.
  • Warns when decompressed size reaches 90% of 52 MB and adds regression coverage.
File Description
packages/​plugins/​apps/​src/​archive.ts Calculates decompressed archive size.
packages/​plugins/​apps/​src/​constants.ts Defines size limit and warning ratio.
packages/​plugins/​apps/​src/​vite/​build-package.ts Logs package sizes and emits warnings.
packages/​plugins/​apps/​src/​vite/​build-backend-functions.ts Minifies production backend bundles.
packages/​plugins/​apps/​src/​vite/​build-backend-functions.test.ts Tests minification and preserved names.
packages/​plugins/​apps/​src/​index.test.ts Tests size reporting and warning boundaries.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/plugins/apps/src/vite/build-backend-functions.test.ts Outdated
Comment thread packages/plugins/apps/src/vite/build-backend-functions.test.ts Outdated
@ksun154
ksun154 marked this pull request as ready for review October 1, 2026 20:55
@ksun154
ksun154 requested a review from a team as a code owner October 1, 2026 20:55
@ksun154
ksun154 requested review from sdkennedy2 and removed request for a team October 1, 2026 20:55
@ksun154 ksun154 changed the title [APPS] Minify backend bundles and warn near the 52 MB limit [APPS] Minify backend bundles Oct 1, 2026
@ksun154
ksun154 requested a balanced review from Copilot October 1, 2026 21:03
@ksun154
ksun154 force-pushed the kelly.sun/apps-backend-minify branch from 5bda49b to 2309783 Compare October 1, 2026 21:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation is focused and well tested; only a non-blocking stale comment needs correction.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (2)

Comment thread packages/plugins/apps/src/archive.ts Outdated
Minify production backend bundles with esbuild and keepNames, so function and class names survive in function-log stack traces. Dev-server bundles stay unminified. Every package build now logs its file count, compressed size and decompressed size.
@ksun154
ksun154 force-pushed the kelly.sun/apps-backend-minify branch from 2309783 to 63bb070 Compare October 1, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants