Skip to content
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

perf(ssr): calculate stacktrace offset lazily #13256

Merged
merged 1 commit into from May 22, 2023

Conversation

ohana54
Copy link
Contributor

@ohana54 ohana54 commented May 18, 2023

Description

I'm working on a cli which uses vite as a dependency.
I'm also using the source-map-support package to transform error stacktrace frames.

When running the cli, the vite module is loaded. During the load, it eagerly creates an Error and accesses its stack property, which triggers source mapping.
This is pretty slow and incurs a few hundred ms on my cli's startup time (might be different numbers on different hardware).

Proposed solution - calculate the offset (which accesses stack) lazily - only when we actually need to rewrite an ssr stacktrace.

Additional context

  1. I didn't add a test that will break without this change, don't know if it's possible and/or worth it. Will be happy to add with some help.
  2. I labeled the PR as a refactor, I didn't really know what is the category for that. Is this considered a perf improvement?

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented May 18, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@ohana54 ohana54 changed the title calculate ssr stacktrace offset lazily refactor(ssr): calculate ssr stacktrace offset lazily May 18, 2023
@ohana54 ohana54 marked this pull request as ready for review May 18, 2023 18:00
@sapphi-red sapphi-red changed the title refactor(ssr): calculate ssr stacktrace offset lazily refactor(ssr): calculate stacktrace offset lazily May 22, 2023
@sapphi-red sapphi-red changed the title refactor(ssr): calculate stacktrace offset lazily perf(ssr): calculate stacktrace offset lazily May 22, 2023
@sapphi-red sapphi-red added p2-nice-to-have Not breaking anything but nice to have (priority) feat: ssr labels May 22, 2023
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@patak-dev patak-dev merged commit 906c4c1 into vitejs:main May 22, 2023
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants