Skip to content

ref(core): Simplify core utility functions for smaller bundle#19854

Open
HazAT wants to merge 4 commits intodevelopfrom
bundle-size/core-utils-cleanup
Open

ref(core): Simplify core utility functions for smaller bundle#19854
HazAT wants to merge 4 commits intodevelopfrom
bundle-size/core-utils-cleanup

Conversation

@HazAT
Copy link
Member

@HazAT HazAT commented Mar 17, 2026

Summary

Small, safe simplifications across core utilities. Combined saves ~80 bytes gzipped.

Changes

  • envelope.ts: Slim ITEM_TYPE_TO_DATA_CATEGORY_MAP by removing 7 self-mapping entries (e.g. session: "session"). Falls back to the type name itself.
  • object.ts: Replace getOwnProperties manual for...in + hasOwnProperty loop with Object.fromEntries(Object.entries(obj)). Use shorthand value in addNonEnumerableProperty.
  • baggage.ts: Use .startsWith() instead of .match(regex) for sentry prefix check.
  • browser.ts: Inline allowedAttrs array literal directly in the for...of loop.
  • eventFilters.ts: Convert verbose DEFAULT_IGNORE_ERRORS string literals to shorter regex patterns with equivalent matching behavior (vv().getRestrictions, simulateEvent, solana, _AutofillCallbackHandler).

All changes are behavior-preserving.

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 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 25.52 kB -0.44% -112 B 🔽
@sentry/browser - with treeshaking flags 24.04 kB -0.43% -102 B 🔽
@sentry/browser (incl. Tracing) 42.5 kB -0.27% -115 B 🔽
@sentry/browser (incl. Tracing, Profiling) 47.17 kB -0.23% -105 B 🔽
@sentry/browser (incl. Tracing, Replay) 81.31 kB -0.14% -109 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.88 kB -0.17% -116 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 86.01 kB -0.13% -110 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 98.27 kB -0.11% -104 B 🔽
@sentry/browser (incl. Feedback) 42.35 kB -0.24% -99 B 🔽
@sentry/browser (incl. sendFeedback) 30.2 kB -0.37% -110 B 🔽
@sentry/browser (incl. FeedbackAsync) 35.25 kB -0.31% -109 B 🔽
@sentry/browser (incl. Metrics) 26.81 kB -0.43% -114 B 🔽
@sentry/browser (incl. Logs) 26.95 kB -0.43% -116 B 🔽
@sentry/browser (incl. Metrics & Logs) 27.64 kB -0.38% -103 B 🔽
@sentry/react 27.3 kB -0.34% -93 B 🔽
@sentry/react (incl. Tracing) 44.86 kB -0.21% -91 B 🔽
@sentry/vue 29.99 kB -0.32% -94 B 🔽
@sentry/vue (incl. Tracing) 44.38 kB -0.25% -107 B 🔽
@sentry/svelte 25.55 kB -0.45% -115 B 🔽
CDN Bundle 28.2 kB -0.27% -74 B 🔽
CDN Bundle (incl. Tracing) 43.39 kB -0.27% -117 B 🔽
CDN Bundle (incl. Logs, Metrics) 29.07 kB -0.26% -75 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) 44.26 kB -0.23% -99 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 68.12 kB -0.14% -90 B 🔽
CDN Bundle (incl. Tracing, Replay) 80.23 kB -0.13% -100 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 81.14 kB -0.12% -91 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 85.78 kB -0.11% -91 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.67 kB -0.12% -101 B 🔽
CDN Bundle - uncompressed 82.32 kB -0.37% -304 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 128.25 kB -0.25% -315 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.19 kB -0.36% -304 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 131.11 kB -0.24% -315 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.82 kB -0.15% -304 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 245.1 kB -0.13% -315 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.95 kB -0.13% -315 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 258.01 kB -0.13% -315 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.85 kB -0.13% -315 B 🔽
@sentry/nextjs (client) 47.28 kB -0.19% -86 B 🔽
@sentry/sveltekit (client) 42.95 kB -0.28% -119 B 🔽
@sentry/node-core 56.28 kB -0.12% -62 B 🔽
@sentry/node 173.09 kB -0.04% -66 B 🔽
@sentry/node - without tracing 96.27 kB -0.08% -76 B 🔽
@sentry/aws-serverless 113.28 kB -0.06% -62 B 🔽

View base workflow run

@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,060 - 8,908 +2%
GET With Sentry 1,677 19% 1,713 -2%
GET With Sentry (error only) 6,099 67% 6,093 +0%
POST Baseline 1,201 - 1,190 +1%
POST With Sentry 575 48% 591 -3%
POST With Sentry (error only) 1,057 88% 1,044 +1%
MYSQL Baseline 3,243 - 3,176 +2%
MYSQL With Sentry 493 15% 488 +1%
MYSQL With Sentry (error only) 2,635 81% 2,617 +1%

View base workflow run

HazAT and others added 2 commits March 18, 2026 21:11
A collection of small, safe simplifications across core utilities:

- envelope.ts: Slim ITEM_TYPE_TO_DATA_CATEGORY_MAP by removing 7 self-mapping
  entries (e.g. session→session). Use a fallback to the type name itself.
- object.ts: Replace getOwnProperties manual for-in+hasOwnProperty loop with
  Object.fromEntries(Object.entries(obj)). Use shorthand value in
  addNonEnumerableProperty.
- baggage.ts: Use .startsWith() instead of .match(regex) for prefix check.
- browser.ts: Inline allowedAttrs array literal directly in for-of loop.
- eventFilters.ts: Convert verbose DEFAULT_IGNORE_ERRORS string literals to
  shorter regex patterns with equivalent matching behavior.

All changes are behavior-preserving. Combined saves ~80 bytes gzipped.

Co-Authored-By: Claude claude@anthropic.com
@Lms24 Lms24 force-pushed the bundle-size/core-utils-cleanup branch from 3908220 to 11523b9 Compare March 18, 2026 20:34
@Lms24 Lms24 requested review from a team as code owners March 18, 2026 20:34
@Lms24 Lms24 changed the base branch from autoresearch/browser-bundle-size-2026-03-17 to develop March 18, 2026 20:34
@Lms24 Lms24 changed the title refactor(core): Simplify core utility functions for smaller bundle ref(core): Simplify core utility functions for smaller bundle Mar 18, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 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 ✨

  • (remix) Server Timing Headers Trace Propagation by onurtemizkan in #18653

Bug Fixes 🐛

Deps

  • Bump devalue 5.6.3 to 5.6.4 to fix CVE-2026-30226 by chargome in #19849
  • Bump file-type to 21.3.2 and @nestjs/common to 11.1.17 by chargome in #19847
  • Bump unhead 2.1.4 to 2.1.12 to fix CVE-2026-31860 and CVE-2026-31873 by chargome in #19848
  • Bump flatted 3.3.1 to 3.4.2 to fix CVE-2026-32141 by chargome in #19842
  • Bump tar 7.5.10 to 7.5.11 to fix CVE-2026-31802 by chargome in #19846
  • Bump hono 4.12.5 to 4.12.7 in cloudflare-hono E2E test app by chargome in #19850
  • Bump undici 6.23.0 to 6.24.1 to fix multiple CVEs by chargome in #19841

Other

  • (deno) Clear pre-existing OTel global before registering TracerProvider by sergical in #19723
  • (node-core) Recycle propagationContext for each request by Lms24 in #19835

Internal Changes 🔧

  • (core) Simplify core utility functions for smaller bundle by HazAT in #19854
  • (deps) Bump next from 16.1.5 to 16.1.7 in /dev-packages/e2e-tests/test-applications/nextjs-16 by dependabot in #19851
  • (react) Add gql tests for react router by chargome in #19844
  • (release) Switch from action-prepare-release to Craft by BYK in #18763

🤖 This preview updates automatically when you update the PR.

@Lms24 Lms24 self-assigned this Mar 18, 2026
*/
export function envelopeItemTypeToDataCategory(type: EnvelopeItemType): DataCategory {
return ITEM_TYPE_TO_DATA_CATEGORY_MAP[type];
return DATA_CATEGORY_OVERRIDES[type] || (type as DataCategory);
Copy link
Member

@Lms24 Lms24 Mar 18, 2026

Choose a reason for hiding this comment

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

We need to retain type safety, otherwise we risk introducing incorrect data categories due to the type check. We can fix it with stricter types on the map and a small validation function. We probably still save some bytes compared to the original implementation.

See 11523b9#diff-588d4f33b2a2c626e7622549bdbbb6662455d9b30261667672be6f0af54074c4

Object.defineProperty(obj, name, {
// enumerable: false, // the default, so we can save on bundle size by not explicitly setting it
value: value,
value,
Copy link
Member

Choose a reason for hiding this comment

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

gonna bring back the comment

return extractedProps;
} else {
return {};
return Object.fromEntries(Object.entries(obj));
Copy link
Member

Choose a reason for hiding this comment

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

this is actually a nice improvement!

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