Skip to content

Conversation

@AbhiPrasad
Copy link
Member

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

@github-actions
Copy link
Contributor

github-actions bot commented Dec 10, 2021

size-limit report

Path Base Size (5216184) Current Size Change
@sentry/browser - CDN Bundle (gzipped) 22.45 KB 22.37 KB -0.33% 🔽
@sentry/browser - Webpack 23.29 KB 23.21 KB -0.33% 🔽
@sentry/browser - Webpack - gzip = false 82.73 KB 81.68 KB -1.28% 🔽
@sentry/react - Webpack 23.32 KB 23.24 KB -0.33% 🔽
@sentry/nextjs Client - Webpack 48.07 KB 47.96 KB -0.24% 🔽
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 29.98 KB 29.94 KB -0.15% 🔽

@AbhiPrasad
Copy link
Member Author

lol I messed up size bot

image

lemme fix

if (this._options.history) {
addInstrumentationHandler({
callback: (...args) => {
this._historyBreadcrumb(...args);
Copy link
Member Author

Choose a reason for hiding this comment

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

a lot of these wins are by rm -rf the spread operator ^^

*/
public setupOnce(): void {
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
const hub = getCurrentHub();
Copy link
Member Author

Choose a reason for hiding this comment

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

The change to using a local hub vs. the global getCurrentHub is more correct, and will help when we switch to passing in the hub/client explicitly.

@AbhiPrasad
Copy link
Member Author

AbhiPrasad commented Dec 10, 2021

I tried doing dynamic dispatch (haha yes insert callOnHub joke here) to reduce the if statement chain in setupOnce but it didn't really help. Saving this example for the future.

// eslint-disable-next-line guard-for-in
for (const key in this._options) {
  const val = this._options[key as keyof BreadcrumbsOptions];
  if (key === DOM) {
    _addDomBreadcrumbs(addBreadcrumb, val);
  } else if (key !== 'sentry') {
    DISPATCH[key as keyof Omit<BreadcrumbsOptions, 'dom' | 'sentry'>](addBreadcrumb);
  }
}

const DISPATCH: {
  [P in keyof Omit<BreadcrumbsOptions, 'dom' | 'sentry'>]: (addBreadcrumb: AddBreadcrumb) => void;
} = {
  console: _addConsoleBreadcrumbs,
  fetch: _addFetchBreadcrumbs,
  history: _addHistoryBreadcrumbs,
  xhr: _addXhrBreadcrumbs,
};

Edit: This is because if statements are very efficient:

this.at.xhr && function(t) {
    st(function(n) {
        if (n.endTimestamp && !n.xhr.__sentry_own_request__) {
            var r = n.xhr.__sentry_xhr__ || {},
                i = r.method,
                e = r.url,
                o = r.status_code,
                u = r.body;
            t({
                category: Zn,
                data: {
                    method: i,
                    url: e,
                    status_code: o
                },
                type: "http"
            }, {
                xhr: n.xhr,
                input: u
            })
        }
    }, Zn)
}(o)

@AbhiPrasad AbhiPrasad force-pushed the abhi-add-instrumentation-handler-exp branch from ebf7a7d to 3c91f6f Compare December 10, 2021 22:23
@AbhiPrasad AbhiPrasad added this to the Treeshaking / Bundle Size milestone Dec 11, 2021
@AbhiPrasad
Copy link
Member Author

Gonna try to merge in #4265 first

@AbhiPrasad
Copy link
Member Author

Closing - will revisit after #4279 gets merged in

@AbhiPrasad AbhiPrasad closed this Dec 14, 2021
@AbhiPrasad AbhiPrasad deleted the abhi-add-instrumentation-handler-exp branch December 14, 2021 19:15
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