[APPS] Tree-shake backend function bundles - #538
Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits intoOct 2, 2026
Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
gh-worker-dd-mergequeue-cf854d[bot] merged 3 commits into
Conversation
Each exported backend function is bundled by its own vite.build(), and treeshake: false made every bundle carry the full import graph of its .backend.ts file, including code only sibling exports use. Enable standard tree-shaking so each bundle contains only what its function reaches.
|
✅ All CI checks and tests passed. 🎉 All green!🧪 All tests passed 🔗 Commit SHA: a243726 | Docs | View more details | Give us feedback! |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new test violates the repository’s no-inlined-function-call-arguments standard.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Enables backend bundle tree-shaking to reduce duplicated code across separately bundled exports.
Changes:
- Enables Rollup tree-shaking for backend builds.
- Adds regression coverage for unused exports and import-time side effects.
| File | Description |
|---|---|
packages/plugins/apps/src/vite/build-config.ts |
Enables and documents tree-shaking. |
packages/plugins/apps/src/vite/build-config.test.ts |
Tests retained side effects and removed unused code. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
tyffical
approved these changes
Oct 1, 2026
…end-treeshake # Conflicts: # packages/plugins/apps/src/vite/build-config.test.ts
gh-worker-dd-mergequeue-cf854d
Bot
deleted the
kelly.sun/apps-backend-treeshake
branch
October 2, 2026 15:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What and why?
This is an alternative to #533 for the pitchGPT HTTP 413 failure ("bundle exceeds the maximum decompressed size of 52 MB").
Each exported backend function is bundled by its own
vite.build(), from a virtual entry that imports only that one export. The shared backend config setrollupOptions.treeshake: false, soRollup kept every module the
.backend.tsfile imports, including code that only sibling exports use. A file with N exports therefore shipped N copies of its whole import graph. That is the"14× for the largest file" multiplier in #533. Minifying makes each copy smaller but keeps all of them; tree-shaking removes the duplication.
I found no stated reason for
treeshake: false. It arrived with the switch to separatevite.build()calls in e154acf, with no comment or commit-message rationale.This PR only enables tree-shaking. It does not minify;
minify: falseis unchanged.How?
packages/plugins/apps/src/vite/build-config.ts:treeshake: false→treeshake: true. Production and dev-server builds share this config."sideEffects": false, which is the same behavior as thefrontend build.
moduleParsed, which happens before tree-shaking. They still see every imported module, so allowlists and banned-import detection areunchanged.
setBackend/setExecuteActionImplementationcalls run insidemain(), so they are reachable and kept.Testing
build-config.test.ts. It runs a real Vite build and checks that:master(the sibling-only code is present in the bundle) and passes with this change.packages/plugins/apps: 35 suites, 747 passed, 1 skipped. This includes the real@datadog/apps-backendSDK integration build and the local-execution suites.tsc --noEmitare clean.Measurements
Both builds have minification off.
apps_backend_project, 7 functions),mastermasterThe fixture has about one export per file, so it understates the gain for apps with many exports per file. pitchGPT has not been measured yet.
Risks and follow-ups
"sideEffects": falsebut relies on import-time code would lose that code. The frontend build has the same exposure. Fallback:treeshake: { moduleSideEffects: true }, at the cost of keeping more unused code.apps.backend.minifyoption. A lighter variant (esbuild: { minifyIdentifiers: false }, untested) keeps local names readable.