Skip to content

ref(browser): Split stack line parsers into individual functions and simplify further #4555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Feb 14, 2022

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Feb 11, 2022

  • Converts parsers into individual functions now in stack-parsers.ts
  • Removes TraceKitStackTrace and instead just returns StackFrame[]
  • Replaces exceptionFromStacktrace(computeStackTrace(e)) with exceptionFromError(e))
  • Replaces eventFromStacktrace(computeStackTrace(e)) with eventFromError(e))
  • Changes tests to test against a full Exception which meant frames needed reversing and in_app adding
  • Moves createStackParser and StackLineParser type to @sentry/utils where there was already a stacktrace.ts
  • Renamed prepareFramesForEvent to stripSentryFramesAndReverse and moved to utils too. This is nearly identical to the node.js code and means the parser now returns frames ready to go into Exception
  • Moved in_app to createFrame in stack parsers since everything browser is considered in_app
  • Simplified frame popping so it occurs before parsing. ie. stack.split('\n').slice(skipFirst)

@timfish
Copy link
Collaborator Author

timfish commented Feb 11, 2022

For reference, the entire stack-parsers.ts which includes all the line parsers now minifies down to 1790 bytes:

function e(e,n,o,t){return{filename:e,function:n,lineno:o,colno:t}}const n=/^\s*at (?:(.*?) ?\((?:address at )?)?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,o=/\((\S*)(?::(\d+))(?::(\d+))\)/;export const chrome=t=>{const i=n.exec(t);if(i){if(i[2]&&0===i[2].indexOf("eval")){const e=o.exec(i[2]);e&&(i[2]=e[1],i[3]=e[2],i[4]=e[3])}const[n,t]=r(i[1]||"?",i[2]);return e(t,n,i[3]?+i[3]:void 0,i[4]?+i[4]:void 0)}};const t=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:file|https?|blob|chrome|webpack|resource|moz-extension|capacitor).*?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i,i=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i;export const gecko=n=>{const o=t.exec(n);if(o){if(o[3]&&o[3].indexOf(" > eval")>-1){const e=i.exec(o[3]);e&&(o[1]=o[1]||"eval",o[3]=e[1],o[4]=e[2],o[5]="")}let n=o[3],t=o[1]||"?";return[t,n]=r(t,n),e(n,t,o[4]?+o[4]:void 0,o[5]?+o[5]:void 0)}};const s=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;export const winjs=n=>{const o=s.exec(n);return o?e(o[2],o[1]||"?",+o[3],o[4]?+o[4]:void 0):void 0};const c=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i;export const opera10=n=>{const o=c.exec(n);return o?e(o[2],o[3]||"?",+o[1]):void 0};const d=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\(.*\))? in (.*):\s*$/i;export const opera11=n=>{const o=d.exec(n);return o?e(o[5],o[3]||o[4]||"?",+o[1],+o[2]):void 0};const r=(e,n)=>{const o=-1!==e.indexOf("safari-extension"),t=-1!==e.indexOf("safari-web-extension");return o||t?[-1!==e.indexOf("@")?e.split("@")[0]:"?",o?safari-extension:${n}:safari-web-extension:${n}]:[e,n]};

Dropping default Opera support for v7 will save us another ~360 bytes.

@timfish timfish marked this pull request as draft February 11, 2022 15:00
@AbhiPrasad AbhiPrasad added this to the Treeshaking / Bundle Size milestone Feb 11, 2022
@timfish timfish mentioned this pull request Feb 11, 2022
15 tasks
@timfish
Copy link
Collaborator Author

timfish commented Feb 11, 2022

Sorry, this PR got a lot bigger than I wanted. It needed a lot of extra changes to get the tests passing.

The good news is that the integration tests are working well!

@timfish timfish marked this pull request as ready for review February 11, 2022 16:56
@timfish
Copy link
Collaborator Author

timfish commented Feb 11, 2022

It looks like overall this results in 70 byte increase for ES5 min bundle and almost no change for ES6 min.

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Super busy, but one quick comment I saw, will come back and do a full review on monday!

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

thanks Tim!

@AbhiPrasad AbhiPrasad merged commit 858c2f7 into getsentry:master Feb 14, 2022
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