Skip to content

perf: improve isFileReadable performance#6868

Merged
patak-cat merged 2 commits intovitejs:mainfrom
Demivan:is-file-readable-perf
Feb 13, 2022
Merged

perf: improve isFileReadable performance#6868
patak-cat merged 2 commits intovitejs:mainfrom
Demivan:is-file-readable-perf

Conversation

@Demivan
Copy link
Contributor

@Demivan Demivan commented Feb 11, 2022

Description

accessSync used in isFileReadable is slow because it throws and Node spends significant time generating stack trace.
This PR uses statSync with throwIfNoEntry: false parameter to make it not throw.

Build performance improvement on my machine was around 10%.

Additional context

After profiling Vite 2.7 I found that resolve package is slow. After updating Vite, performance issue with resolve package was fixed, but I saw the same stack trace in Vite code. Tracked down resolve solution to this issue browserify/resolve#255. Backported this solution to Vite.

I could not find mentioned in the comment issue to test for that case. #2051 looks completely unrelated.


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 Commit 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.

@Niputi Niputi added the p4-important Violate documented behavior or significantly improves performance (priority) label Feb 11, 2022
patak-cat
patak-cat previously approved these changes Feb 11, 2022
@patak-cat
Copy link
Member

This looks great, and I think we can get it in the next patch. Thanks @Demivan!

@Demivan Demivan force-pushed the is-file-readable-perf branch from 4a43081 to 3231932 Compare February 13, 2022 08:47
@Demivan Demivan requested a review from patak-cat February 13, 2022 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p4-important Violate documented behavior or significantly improves performance (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants