Skip to content

refactor(browser): Reduce browser package bundle size#19856

Open
HazAT wants to merge 1 commit intoautoresearch/browser-bundle-size-2026-03-17from
bundle-size/browser-cleanup
Open

refactor(browser): Reduce browser package bundle size#19856
HazAT wants to merge 1 commit intoautoresearch/browser-bundle-size-2026-03-17from
bundle-size/browser-cleanup

Conversation

@HazAT
Copy link
Member

@HazAT HazAT commented Mar 17, 2026

Summary

A collection of small, safe optimizations across the browser package. Combined saves ~60 bytes gzipped.

Changes

File Change Impact
helpers.ts + stacktrace.ts Rename internal sentryWrappedsW in wrap(). Update frame stripping regex to match both names. ~10B gzip
breadcrumbs.ts Remove unused breadcrumbData variable from fetch handler dead code
browserapierrors.ts Encode DEFAULT_EVENT_TARGET as string.split(",") instead of array literal 51B raw
globalhandlers.ts Remove redundant intermediate variable aliases in _enhanceEventWithInitialFrame cleaner code
detectBrowserExtension.ts Replace array.some(startsWith) with single regex test ~3B gzip
eventbuilder.ts Simplify getErrorPropertyFromObject to Object.values().find() ~9B gzip
lazyLoadIntegration.ts Derive CDN bundle filenames from integration names instead of storing duplicate key-value pairs ~30B gzip

lazyLoadIntegration detail

The LazyLoadableIntegrations object stored 21 key-value pairs where values were mostly derivable from keys (strip "Integration", lowercase). Replaced with:

  • An array of integration names (encoded as string.split(","))
  • A derivation function
  • A 3-entry exceptions map for hyphenated names (replay-canvas, feedback-modal, feedback-screenshot)

All changes are behavior-preserving. No public API modifications.

Part of #19833.

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

A collection of small, safe optimizations across the browser package:

- helpers.ts: Rename internal `sentryWrapped` function to `sW` in the
  wrap() helper. Update the frame stripping regex in core/stacktrace.ts
  to match both names for backwards compatibility. Saves ~10B gzipped.
- breadcrumbs.ts: Remove unused `breadcrumbData` variable from the fetch
  breadcrumb handler — it was constructed but never used in either branch.
- browserapierrors.ts: Encode DEFAULT_EVENT_TARGET as comma-separated
  string.split() instead of array literal. Saves 51B raw.
- globalhandlers.ts: Remove redundant intermediate variable aliases in
  _enhanceEventWithInitialFrame.
- detectBrowserExtension.ts: Replace array.some(startsWith) with a single
  regex test for extension protocol detection.
- eventbuilder.ts: Simplify getErrorPropertyFromObject to use
  Object.values().find() instead of manual for-in loop.
- lazyLoadIntegration.ts: Derive CDN bundle filenames from integration
  names instead of storing duplicate key-value pairs. Uses a 3-entry
  exceptions map for hyphenated names (replay-canvas, feedback-modal,
  feedback-screenshot). Saves ~30B gzipped.

All changes are behavior-preserving. No public API modifications.

Co-Authored-By: Claude claude@anthropic.com
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.

const sentryWrapped = function (this: unknown, ...args: unknown[]): unknown {
// It is important that `sW` is not an arrow function to preserve the context of `this`
// The name `sW` is matched by the frame stripping regex in stacktrace.ts
const sW = function (this: unknown, ...args: unknown[]): unknown {
Copy link

Choose a reason for hiding this comment

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

Wrapper rename breaks minified frame stripping

High Severity

Renaming the wrapper function to sW changes the stack-frame marker, but terser still only reserves sentryWrapped. In minified CDN builds, sW can be mangled, so stripSentryFramesAndReverse no longer recognizes and removes the internal wrapper frame.

Additional Locations (1)
Fix in Cursor Fix in Web

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.59 kB added added
@sentry/browser - with treeshaking flags 24.1 kB added added
@sentry/browser (incl. Tracing) 42.58 kB added added
@sentry/browser (incl. Tracing, Profiling) 47.25 kB added added
@sentry/browser (incl. Tracing, Replay) 81.38 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.95 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 86.08 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 98.31 kB added added
@sentry/browser (incl. Feedback) 42.38 kB added added
@sentry/browser (incl. sendFeedback) 30.25 kB added added
@sentry/browser (incl. FeedbackAsync) 35.25 kB added added
@sentry/browser (incl. Metrics) 26.89 kB added added
@sentry/browser (incl. Logs) 27.04 kB added added
@sentry/browser (incl. Metrics & Logs) 27.72 kB added added
@sentry/react 27.35 kB added added
@sentry/react (incl. Tracing) 44.89 kB added added
@sentry/vue 30.04 kB added added
@sentry/vue (incl. Tracing) 44.46 kB added added
@sentry/svelte 25.62 kB added added
CDN Bundle 28.2 kB added added
CDN Bundle (incl. Tracing) 43.41 kB added added
CDN Bundle (incl. Logs, Metrics) 29.06 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 44.26 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 68.12 kB added added
CDN Bundle (incl. Tracing, Replay) 80.25 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 81.16 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 85.8 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.67 kB added added
CDN Bundle - uncompressed 82.33 kB added added
CDN Bundle (incl. Tracing) - uncompressed 128.27 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.2 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 131.13 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.83 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 245.12 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.97 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 258.03 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.88 kB added added
@sentry/nextjs (client) 47.33 kB added added
@sentry/sveltekit (client) 43.02 kB added added
@sentry/node-core 56.34 kB added added
@sentry/node 173.17 kB added added
@sentry/node - without tracing 96.35 kB added added
@sentry/aws-serverless 113.35 kB added added

@github-actions
Copy link
Contributor

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 11,399 - - added
GET With Sentry 2,027 18% - added
GET With Sentry (error only) 7,717 68% - added
POST Baseline 1,213 - - added
POST With Sentry 603 50% - added
POST With Sentry (error only) 1,082 89% - added
MYSQL Baseline 3,996 - - added
MYSQL With Sentry 717 18% - added
MYSQL With Sentry (error only) 3,276 82% - added

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.

1 participant