Skip to content

perf(build): Optimize terser minifier config for CDN bundles#19852

Open
HazAT wants to merge 2 commits intoautoresearch/browser-bundle-size-2026-03-17from
bundle-size/terser-config
Open

perf(build): Optimize terser minifier config for CDN bundles#19852
HazAT wants to merge 2 commits intoautoresearch/browser-bundle-size-2026-03-17from
bundle-size/terser-config

Conversation

@HazAT
Copy link
Member

@HazAT HazAT commented Mar 17, 2026

Summary

Enable additional terser compress and mangle options that safely reduce CDN .min.js bundle sizes. Saves ~300 bytes gzipped on the base browser bundle.

Changes

Option Effect
compress.passes: 5 Multi-pass optimization finds more dead code
compress.ecma: 2020 Allows modern syntax in output (nullish coalescing, optional chaining)
compress.toplevel: true Better variable inlining within the IIFE wrapper
compress.unsafe_arrows: true Converts function to => where this is unused (~1.3KB raw)
compress.unsafe_methods: true Shorthand method syntax { m(){} }
compress.unsafe_comps / unsafe_math / pure_getters Safe algebraic optimizations
mangle.toplevel: true Mangle top-level variable names inside IIFE scope

These options only affect CDN .min.js bundles, not npm ESM/CJS output. The unsafe_* options are safe for our codebase because the CDN bundles run in browser contexts where the assumptions hold.

Also pre-reserves sW in the mangle list for a follow-up change.

Part of #19833.

Co-Authored-By: Claude claude@anthropic.com

@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.64 kB added added
@sentry/browser - with treeshaking flags 24.14 kB added added
@sentry/browser (incl. Tracing) 42.62 kB added added
@sentry/browser (incl. Tracing, Profiling) 47.28 kB added added
@sentry/browser (incl. Tracing, Replay) 81.42 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 71 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 86.12 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 98.37 kB added added
@sentry/browser (incl. Feedback) 42.45 kB added added
@sentry/browser (incl. sendFeedback) 30.31 kB added added
@sentry/browser (incl. FeedbackAsync) 35.36 kB added added
@sentry/browser (incl. Metrics) 26.92 kB added added
@sentry/browser (incl. Logs) 27.07 kB added added
@sentry/browser (incl. Metrics & Logs) 27.74 kB added added
@sentry/react 27.39 kB added added
@sentry/react (incl. Tracing) 44.95 kB added added
@sentry/vue 30.08 kB added added
@sentry/vue (incl. Tracing) 44.48 kB added added
@sentry/svelte 25.66 kB added added
CDN Bundle 28.1 kB added added
CDN Bundle (incl. Tracing) 43.18 kB added added
CDN Bundle (incl. Logs, Metrics) 28.95 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 44.06 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 67.88 kB added added
CDN Bundle (incl. Tracing, Replay) 79.92 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.83 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 85.46 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.39 kB added added
CDN Bundle - uncompressed 81.02 kB added added
CDN Bundle (incl. Tracing) - uncompressed 126.58 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 83.84 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 129.4 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 206.15 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 242.17 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 244.99 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 254.94 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 257.76 kB added added
@sentry/nextjs (client) 47.37 kB added added
@sentry/sveltekit (client) 43.07 kB added added
@sentry/node-core 56.24 kB added added
@sentry/node 173.06 kB added added
@sentry/node - without tracing 96.25 kB added added
@sentry/aws-serverless 113.25 kB added added

@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,205 - - added
GET With Sentry 1,664 18% - added
GET With Sentry (error only) 5,862 64% - added
POST Baseline 1,202 - - added
POST With Sentry 596 50% - added
POST With Sentry (error only) 1,054 88% - added
MYSQL Baseline 3,254 - - added
MYSQL With Sentry 493 15% - added
MYSQL With Sentry (error only) 2,674 82% - added

@isaacs isaacs force-pushed the bundle-size/terser-config branch from 56e885a to 3bc0473 Compare March 19, 2026 14:31
@isaacs isaacs requested review from a team as code owners March 19, 2026 14:31
@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Deps

  • Bump yauzl from 3.2.0 to 3.2.1 by dependabot in #19809
  • Bump mysql2 from 3.14.4 to 3.19.1 by dependabot in #19787
  • Bump OpenTelemetry dependencies by andreiborza in #19682
  • Bump hono from 4.12.5 to 4.12.7 by dependabot in #19747
  • Bump simple-git from 3.30.0 to 3.33.0 by dependabot in #19744

Nestjs

  • Instrument @nestjs/bullmq by nicohrubec in #19759
  • Use more specific span origins for NestJS guards, pipes, interceptors, and exception filters by nicohrubec in #19751
  • Instrument @nestjs/schedule decorators by nicohrubec in #19735

Node

  • Avoid OTEL instrumentation for outgoing requests on Node 22+ by mydea in #17355
  • Expose headersToSpanAttributes option on nativeNodeFetchIntegration by andreiborza in #19770

Other

  • (astro) Add Astro 6 support by Lms24 in #19745
  • (browser/cloudflare) Export conversation id from browser and cloudflare runtimes by nicohrubec in #19820
  • (core) Add sentry.timestamp.sequence attribute for timestamp tie-breaking by logaretm in #19421
  • (nextjs) Vercel queue instrumentation by chargome in #19799

Bug Fixes 🐛

Core

  • Fallback to sendDefaultPii setting in langchain and langgraph in non-node environments by nicohrubec in #19813
  • Align Vercel embedding spans with semantic conventions by nicohrubec in #19795
  • Improve Vercel AI SDK instrumentation attributes by RulaKhaled in #19717

Nextjs

  • Strip sourceMappingURL comments after deleting source maps in turbopack builds by chargome in #19814
  • Log correct lastEventId when error is thrown in component render by s1gr1d in #19764

Other

  • (browser) Skip browserTracingIntegration setup for bot user agents by chargome in #19708
  • (cloudflare) Recreate client when previous one was disposed by JPeer264 in #19727
  • (hono) Allow passing env and fix type issues by s1gr1d in #19825
  • (nestjs) Fork isolation scope in @nestjs/event-emitter instrumentation by nicohrubec in #19725
  • (nuxt) Upload client source maps by s1gr1d in #19805
  • (profiling-node) Fix NODE_VERSION rendered as [object Object] in warning by logaretm in #19788

Documentation 📚

New Release

  • Document sdkName for craft by s1gr1d in #19736
  • Update docs based on new Craft flow by s1gr1d in #19731

Other

  • (hono) Document usage without "*" by s1gr1d in #19756

Internal Changes 🔧

  • (agents) Be more explicit on linting and formatting by chargome in #19803
  • (astro,cloudflare) Add an E2E test for Astro 6 on Cloudflare by JPeer264 in #19781
  • (browser) Add simulated mfe integration test by chargome in #19768
  • (build) Optimize terser minifier config for CDN bundles by HazAT in #19852
  • (cloudflare) Prepare for WorkerEntrypoint by JPeer264 in #19742
  • (core) Fix flaky metric sequence number test by nicohrubec in #19754
  • (deps) Bump tedious from 18.6.1 to 19.2.1 by dependabot in #19786
  • (deps-dev) Bump file-type from 20.5.0 to 21.3.1 by dependabot in #19748
  • (e2e) Add MFE e2e test using vite-plugin-federation by chargome in #19778
  • (lint) Rule adjustments and fix warnings by logaretm in #19612
  • (nestjs) Move event instrumentation unit tests to separate file by nicohrubec in #19738
  • (nextjs) Add vercel queue tests to next-16 by chargome in #19798
  • (skills) Add skill-creator and update managed agent skills by chargome in #19713
  • Add oxlint migration commits to blame ignore by logaretm in #19784
  • Bump oxlint and oxfmt by logaretm in #19771
  • Clean up lint and format script names by logaretm in #19719
  • Add oxlint typescript program suppression to workspace settings by logaretm in #19692
  • Auto changes made from "yarn fix" by JPeer264 in #19710

🤖 This preview updates automatically when you update the PR.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Enable additional terser compress and mangle options that safely reduce
the size of CDN bundle .min.js files:

- compress.passes: 5 (multi-pass finds more dead code)
- compress.ecma: 2020 (allows modern syntax: nullish coalescing, optional chaining)
- compress.toplevel: true (better variable inlining within the IIFE)
- compress.unsafe_arrows: true (function → arrow where this is unused, ~1.3KB raw)
- compress.unsafe_methods: true ({ m: function(){} } → { m(){} })
- compress.unsafe_comps/unsafe_math/pure_getters: safe algebraic opts
- mangle.toplevel: true (mangle top-level names inside IIFE scope)

Also adds 'sW' to the mangle reserved list (used by a follow-up change that
shortens the sentryWrapped function name for frame stripping).

These options only affect CDN .min.js bundles, not npm ESM/CJS output.
Saves ~300 bytes gzipped on the base browser bundle.

Co-Authored-By: Claude claude@anthropic.com
@isaacs isaacs force-pushed the bundle-size/terser-config branch from 3bc0473 to 05a894e Compare March 19, 2026 14:37
This prevents the terser mangle option from mangling the 'Sentry' name,
and avoids a terser bug where our top-level 'var Sentry=' gets stripped.
@isaacs isaacs force-pushed the bundle-size/terser-config branch from 05a894e to 9ae982f Compare March 19, 2026 16:20
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