ref(core): Simplify core utility functions for smaller bundle#19854
ref(core): Simplify core utility functions for smaller bundle#19854
Conversation
size-limit report 📦
|
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.
|
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
3908220 to
11523b9
Compare
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛Deps
Other
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
packages/core/src/utils/envelope.ts
Outdated
| */ | ||
| export function envelopeItemTypeToDataCategory(type: EnvelopeItemType): DataCategory { | ||
| return ITEM_TYPE_TO_DATA_CATEGORY_MAP[type]; | ||
| return DATA_CATEGORY_OVERRIDES[type] || (type as DataCategory); |
There was a problem hiding this comment.
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, |
| return extractedProps; | ||
| } else { | ||
| return {}; | ||
| return Object.fromEntries(Object.entries(obj)); |
There was a problem hiding this comment.
this is actually a nice improvement!
Summary
Small, safe simplifications across core utilities. Combined saves ~80 bytes gzipped.
Changes
ITEM_TYPE_TO_DATA_CATEGORY_MAPby removing 7 self-mapping entries (e.g.session: "session"). Falls back to the type name itself.getOwnPropertiesmanualfor...in+hasOwnPropertyloop withObject.fromEntries(Object.entries(obj)). Use shorthandvalueinaddNonEnumerableProperty..startsWith()instead of.match(regex)for sentry prefix check.allowedAttrsarray literal directly in thefor...ofloop.DEFAULT_IGNORE_ERRORSstring 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