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

Vite 2.7.x is about 1.9 to 6.2 times slower than 2.6.14 #6030

Closed
Lani opened this issue Dec 9, 2021 · 30 comments
Closed

Vite 2.7.x is about 1.9 to 6.2 times slower than 2.6.14 #6030

Lani opened this issue Dec 9, 2021 · 30 comments
Labels
p4-important Violate documented behavior or significantly improves performance (priority) performance Performance related enhancement

Comments

@Lani
Copy link

Lani commented Dec 9, 2021

Describe the bug

When upgrading from vite 2.6.14 to 2.7.x the development build performance is about 6.2 times slower on Windows and 1.9 times slower on Ubuntu 20.04 running in WSL2.

Results in seconds on Windows 10:

2.6.14: 12, 7, 7, 6, 6
2.7.1: 46, 47, 46, 47, 48

2.7 is about 6.2 times slower.

Results on Ubuntu 20.04 in WSL2:

2.6.14: 3, 4, 4, 4, 4
2.7.1: 7, 7, 8, 8, 6

2.7 is about 1.9 times slower.

Times rounded to nearest second.

Reproduction

Example repo: https://github.com/Lani/vite-2.7-slow

Steps to reproduce:

  1. npm i
  2. npm run dev -- --force

Use --force to always start without the cache

System Info

Windows

  System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
    Memory: 20.85 GB / 39.75 GB
  Binaries:
    Node: 14.15.4 - C:\Tools\nodejs\node.EXE
    npm: 6.14.10 - C:\Tools\nodejs\npm.CMD
  Browsers:
    Chrome: 96.0.4664.93
    Edge: Spartan (44.19041.1266.0), Chromium (96.0.1054.43)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    @vitejs/plugin-react: ^1.1.0 => 1.1.1
    vite: ^2.7.1 => 2.7.1

Ubuntu:

  System:
    OS: Linux 4.19 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
    Memory: 30.14 GB / 31.17 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node
    npm: 7.24.1 - ~/.nvm/versions/node/v14.15.4/bin/npm
  npmPackages:
    @vitejs/plugin-react: ^1.1.0 => 1.1.1
    vite: ^2.7.1 => 2.7.1

Used Package Manager

npm

No notable difference when using pnpm instead of npm.

Logs

Windows log:

  vite:config bundled config file loaded in 425.78ms +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:react-babel',
  vite:config     'vite:react-refresh',
  vite:config     'vite:react-jsx',
  vite:config     'vite:modulepreload-polyfill',  
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-script-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:client-inject',
  vite:config     'vite:import-analysis'
  vite:config   ],
  vite:config   server: { force: true, fs: { strict: true, allow: [Array], deny: [Array] } },
  vite:config   resolve: { dedupe: [ 'react', 'react-dom' ], alias: [ [Object], [Object] ] },
  vite:config   optimizeDeps: {
  vite:config     include: [ 'react/jsx-dev-runtime' ],
  vite:config     esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
  vite:config   },
  vite:config   configFile: 'C:/code/_labs/vite-default/vite.config.ts',
  vite:config   configFileDependencies: [ 'vite.config.ts' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     server: { force: true, fs: [Object] }
  vite:config   },
  vite:config   root: 'C:/code/_labs/vite-default',
  vite:config   base: '/',
  vite:config   publicDir: 'C:\\code\\_labs\\vite-default\\public',
  vite:config   cacheDir: 'C:\\code\\_labs\\vite-default\\node_modules\\.vite',
  vite:config   command: 'serve',
  vite:config   mode: 'development',
  vite:config   isProduction: false,
  vite:config   build: {
  vite:config     target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     polyfillModulePreload: true,
  vite:config     outDir: 'C:\\code\\_labs\\vite-default\\dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
  vite:config     sourcemap: false,
  vite:config     rollupOptions: { input: 'C:\\code\\_labs\\vite-default\\index.html' },
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined
  vite:config   },
  vite:config   env: { BASE_URL: '/', MODE: 'development', DEV: true, PROD: false },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(0) {},
  vite:config   createResolver: [Function: createResolver]
  vite:config } +13ms
  vite:deps Crawling dependencies using entries:
  vite:deps   C:\code\_labs\vite-default\index.html +0ms
  vite:resolve 4.14ms C:\code\_labs\vite-default\index.html -> C:/code/_labs/vite-default/index.html +0ms
  vite:resolve 1.17ms /src/main.tsx -> C:/code/_labs/vite-default/src/main.tsx +29ms
  vite:resolve 7.34ms react -> C:/code/_labs/vite-default/node_modules/react/index.js +13ms
  vite:resolve 5.92ms react-dom -> C:/code/_labs/vite-default/node_modules/react-dom/index.js +7ms
  vite:resolve 2.83ms ./App -> C:/code/_labs/vite-default/src/App.tsx +16ms
  vite:resolve 5.57ms @mui/material -> C:/code/_labs/vite-default/node_modules/@mui/material/index.js +10ms
  vite:resolve 3.88ms @mui/icons-material -> C:/code/_labs/vite-default/node_modules/@mui/icons-material/esm/index.js +7ms
  vite:resolve 4.01ms @mui/styles -> C:/code/_labs/vite-default/node_modules/@mui/styles/index.js +8ms
  vite:deps Scan completed in 119.05ms: {
  react: 'C:/code/_labs/vite-default/node_modules/react/index.js',
  'react-dom': 'C:/code/_labs/vite-default/node_modules/react-dom/index.js',
  '@mui/material': 'C:/code/_labs/vite-default/node_modules/@mui/material/index.js',
  '@mui/icons-material': 'C:/code/_labs/vite-default/node_modules/@mui/icons-material/esm/index.js',
  '@mui/styles': 'C:/code/_labs/vite-default/node_modules/@mui/styles/index.js'
} +118ms
  vite:resolve 4.99ms react/jsx-dev-runtime -> C:/code/_labs/vite-default/node_modules/react/jsx-dev-runtime.js +0ms
Pre-bundling dependencies:
  react
  react-dom
  @mui/material
  @mui/icons-material
  @mui/styles
  (...and 1 more)
(this will be run only when your dependencies or config have changed)
  vite:resolve 5.53ms @mui/utils -> C:/code/_labs/vite-default/node_modules/@mui/utils/esm/index.js +0ms
  vite:resolve 5.85ms object-assign -> C:/code/_labs/vite-default/node_modules/object-assign/index.js +0ms
  vite:resolve 13.07ms react -> C:/code/_labs/vite-default/node_modules/react/index.js +14ms
  vite:resolve 13.49ms @mui/base -> C:/code/_labs/vite-default/node_modules/@mui/base/index.js +28ms
  vite:resolve 7.06ms scheduler -> C:/code/_labs/vite-default/node_modules/scheduler/index.js +67ms
  vite:resolve 36.15ms @mui/private-theming/useTheme -> C:/code/_labs/vite-default/node_modules/@mui/private-theming/useTheme/index.js +103ms
  vite:resolve 36.49ms @babel/runtime/helpers/esm/extends -> C:/code/_labs/vite-default/node_modules/@babel/runtime/helpers/esm/extends.js +0ms
  vite:resolve 36.84ms @mui/private-theming/ThemeProvider -> C:/code/_labs/vite-default/node_modules/@mui/private-theming/ThemeProvider/index.js +1ms     
  vite:resolve 37.34ms jss-plugin-rule-value-function -> C:/code/_labs/vite-default/node_modules/jss-plugin-rule-value-function/dist/jss-plugin-rule-value-function.esm.js +1ms
  vite:resolve 64.19ms scheduler/tracing -> C:/code/_labs/vite-default/node_modules/scheduler/tracing.js +104ms
  vite:resolve 64.44ms @babel/runtime/helpers/esm/objectWithoutPropertiesLoose -> C:/code/_labs/vite-default/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +66ms
  vite:resolve 27.35ms jss-plugin-global -> C:/code/_labs/vite-default/node_modules/jss-plugin-global/dist/jss-plugin-global.esm.js +29ms
  vite:resolve 27.70ms react -> C:/code/_labs/vite-default/node_modules/react/index.js +0ms
  vite:resolve 132.77ms prop-types -> C:/code/_labs/vite-default/node_modules/prop-types/index.js +136ms
  vite:resolve 132.74ms react-is -> C:/code/_labs/vite-default/node_modules/@mui/utils/node_modules/react-is/index.js +1ms
  vite:resolve 43.22ms jss-plugin-nested -> C:/code/_labs/vite-default/node_modules/jss-plugin-nested/dist/jss-plugin-nested.esm.js +49ms
  vite:resolve 42.98ms hoist-non-react-statics -> C:/code/_labs/vite-default/node_modules/hoist-non-react-statics/dist/hoist-non-react-statics.cjs.js +1ms  vite:resolve 43.09ms jss -> C:/code/_labs/vite-default/node_modules/jss/dist/jss.esm.js +0ms
  vite:resolve 43.46ms react-is -> C:/code/_labs/vite-default/node_modules/react-is/index.js +218ms
  vite:resolve 25.53ms clsx -> C:/code/_labs/vite-default/node_modules/clsx/dist/clsx.m.js +35ms
  vite:resolve 26.06ms jss-plugin-camel-case -> C:/code/_labs/vite-default/node_modules/jss-plugin-camel-case/dist/jss-plugin-camel-case.esm.js +1ms
  vite:resolve 21.24ms react/jsx-runtime -> C:/code/_labs/vite-default/node_modules/react/jsx-runtime.js +24ms
  vite:resolve 23.80ms jss-plugin-default-unit -> C:/code/_labs/vite-default/node_modules/jss-plugin-default-unit/dist/jss-plugin-default-unit.esm.js +25ms
  vite:resolve 285.33ms @mui/base/ModalUnstyled -> C:/code/_labs/vite-default/node_modules/@mui/base/ModalUnstyled/index.js +339ms
  vite:resolve 284.60ms @mui/base/TextareaAutosize -> C:/code/_labs/vite-default/node_modules/@mui/base/TextareaAutosize/index.js +1ms
  vite:resolve 284.97ms @mui/base/NoSsr -> C:/code/_labs/vite-default/node_modules/@mui/base/NoSsr/index.js +0ms
  vite:resolve 284.94ms jss-plugin-vendor-prefixer -> C:/code/_labs/vite-default/node_modules/jss-plugin-vendor-prefixer/dist/jss-plugin-vendor-prefixer.esm.js +1ms
  vite:resolve 284.71ms @mui/base/ClickAwayListener -> C:/code/_labs/vite-default/node_modules/@mui/base/ClickAwayListener/index.js +1ms
  vite:resolve 284.78ms @mui/system -> C:/code/_labs/vite-default/node_modules/@mui/system/esm/index.js +1ms
  vite:resolve 285.49ms @mui/base/AutocompleteUnstyled -> C:/code/_labs/vite-default/node_modules/@mui/base/AutocompleteUnstyled/index.js +1ms
  vite:resolve 1053.37ms is-in-browser -> C:/code/_labs/vite-default/node_modules/is-in-browser/dist/module.js +1s
  vite:resolve 1387.42ms jss-plugin-props-sort -> C:/code/_labs/vite-default/node_modules/jss-plugin-props-sort/dist/jss-plugin-props-sort.esm.js +1s
  vite:resolve 1385.79ms @mui/styled-engine -> C:/code/_labs/vite-default/node_modules/@mui/styled-engine/index.js +2ms
  vite:resolve 720.73ms tiny-warning -> C:/code/_labs/vite-default/node_modules/tiny-warning/dist/tiny-warning.esm.js +7s
  vite:resolve 605.37ms react-dom -> C:/code/_labs/vite-default/node_modules/react-dom/index.js +610ms
  vite:resolve 678.20ms css-vendor -> C:/code/_labs/vite-default/node_modules/css-vendor/dist/css-vendor.esm.js +3s
  vite:resolve 678.36ms @mui/material/utils -> C:/code/_labs/vite-default/node_modules/@mui/material/utils/index.js +0ms
  vite:resolve 687.91ms hyphenate-style-name -> C:/code/_labs/vite-default/node_modules/hyphenate-style-name/index.js +697ms
  vite:resolve 602.13ms @emotion/styled -> C:/code/_labs/vite-default/node_modules/@emotion/styled/dist/emotion-styled.browser.esm.js +24s
  vite:resolve 602.50ms @mui/private-theming -> C:/code/_labs/vite-default/node_modules/@mui/private-theming/index.js +1ms
  vite:resolve 600.95ms @babel/runtime/helpers/esm/createClass -> C:/code/_labs/vite-default/node_modules/@babel/runtime/helpers/esm/createClass.js +1ms  
  vite:resolve 428.78ms react-is -> C:/code/_labs/vite-default/node_modules/@mui/material/node_modules/react-is/index.js +434ms
  vite:resolve 429.25ms @mui/base/PopperUnstyled -> C:/code/_labs/vite-default/node_modules/@mui/base/PopperUnstyled/index.js +0ms
  vite:resolve 578.98ms @emotion/react -> C:/code/_labs/vite-default/node_modules/@emotion/react/dist/emotion-react.browser.esm.js +584ms
  vite:resolve 576.90ms @babel/runtime/helpers/esm/inheritsLoose -> C:/code/_labs/vite-default/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +1ms
  vite:resolve 568.55ms react-is -> C:/code/_labs/vite-default/node_modules/@mui/base/node_modules/react-is/index.js +1ms
  vite:resolve 568.97ms @popperjs/core -> C:/code/_labs/vite-default/node_modules/@popperjs/core/lib/index.js +1ms
  vite:resolve 568.87ms react-transition-group -> C:/code/_labs/vite-default/node_modules/react-transition-group/esm/index.js +1ms
  vite:resolve 509.42ms @babel/runtime/helpers/esm/assertThisInitialized -> C:/code/_labs/vite-default/node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js +520ms
  vite:resolve 506.83ms @mui/base/BackdropUnstyled -> C:/code/_labs/vite-default/node_modules/@mui/base/BackdropUnstyled/index.js +1ms
  vite:resolve 40.92ms @babel/runtime/helpers/esm/toConsumableArray -> C:/code/_labs/vite-default/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js +44ms
  vite:resolve 41.43ms @babel/runtime/helpers/extends -> C:/code/_labs/vite-default/node_modules/@babel/runtime/helpers/esm/extends.js +1ms
  vite:resolve 25.99ms @emotion/cache -> C:/code/_labs/vite-default/node_modules/@emotion/cache/dist/emotion-cache.browser.esm.js +638ms
  vite:resolve 553.07ms @mui/base/BadgeUnstyled -> C:/code/_labs/vite-default/node_modules/@mui/base/BadgeUnstyled/index.js +556ms
  vite:resolve 553.73ms @mui/base/SliderUnstyled -> C:/code/_labs/vite-default/node_modules/@mui/base/SliderUnstyled/index.js +1ms
  vite:resolve 553.83ms @mui/base/composeClasses -> C:/code/_labs/vite-default/node_modules/@mui/base/composeClasses/index.js +1ms
  vite:resolve 48.05ms @emotion/is-prop-valid -> C:/code/_labs/vite-default/node_modules/@emotion/is-prop-valid/dist/emotion-is-prop-valid.browser.esm.js 
+50ms
  vite:resolve 27.83ms @emotion/weak-memoize -> C:/code/_labs/vite-default/node_modules/@emotion/weak-memoize/dist/weak-memoize.browser.esm.js +491ms
  vite:resolve 17.80ms @emotion/utils -> C:/code/_labs/vite-default/node_modules/@emotion/utils/dist/emotion-utils.browser.esm.js +334ms
  vite:resolve 16.58ms @emotion/serialize -> C:/code/_labs/vite-default/node_modules/@emotion/serialize/dist/emotion-serialize.browser.esm.js +171ms
  vite:resolve 17.06ms @emotion/sheet -> C:/code/_labs/vite-default/node_modules/@emotion/sheet/dist/emotion-sheet.browser.esm.js +0ms
  vite:resolve 107.55ms dom-helpers/addClass -> C:/code/_labs/vite-default/node_modules/dom-helpers/esm/addClass.js +109ms
  vite:resolve 42.02ms stylis -> C:/code/_labs/vite-default/node_modules/stylis/index.js +44ms
  vite:resolve 42.49ms @emotion/memoize -> C:/code/_labs/vite-default/node_modules/@emotion/memoize/dist/emotion-memoize.browser.esm.js +1ms
  vite:resolve 42.84ms @emotion/hash -> C:/code/_labs/vite-default/node_modules/@emotion/hash/dist/hash.browser.esm.js +0ms
  vite:resolve 73.63ms dom-helpers/removeClass -> C:/code/_labs/vite-default/node_modules/dom-helpers/esm/removeClass.js +75ms
  vite:resolve 19.93ms @emotion/unitless -> C:/code/_labs/vite-default/node_modules/@emotion/unitless/dist/unitless.browser.esm.js +22ms
  vite:deps deps bundled in 44638.17ms +0ms

  vite v2.7.1 dev server running at:

  > Local: http://localhost:3000/
  > Network: use `--host` to expose

  ready in 45672ms.
### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitejs/vite/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitejs.dev/guide).
- [X] Check that there isn't [already an issue](https://github.com/vitejs/vite/issues) that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vitejs.dev/).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
@alfeg
Copy link

alfeg commented Dec 10, 2021

We also experience vendor package size increase 3-4 times. Seems like tree shake is broken in some way. Also, the random part of functionality is broken.

@Lani
Copy link
Author

Lani commented Dec 10, 2021

@alfeg I haven't noticed that, in the example repo that I posted it looks to be the same. But I haven't checked if tree shaking is working as it should in the first place in 2.6 either.

vite v2.6.14 building for production...
✓ 10762 modules transformed.
dist/assets/favicon.17e50649.svg   1.49 KiB
dist/assets/logo.ecc203fb.svg      2.61 KiB
dist/index.html                    0.52 KiB
dist/assets/index.b81c8c87.js      1.70 KiB / gzip: 0.91 KiB
dist/assets/index.cd9c0392.css     0.75 KiB / gzip: 0.48 KiB
dist/assets/vendor.ae31e9b8.js     235.78 KiB / gzip: 78.01 KiB

vite v2.7.1 building for production...
✓ 10762 modules transformed.
dist/assets/favicon.17e50649.svg   1.49 KiB
dist/assets/logo.ecc203fb.svg      2.61 KiB
dist/index.html                    0.52 KiB
dist/assets/index.b81c8c87.js      1.70 KiB / gzip: 0.91 KiB
dist/assets/index.cd9c0392.css     0.75 KiB / gzip: 0.48 KiB
dist/assets/vendor.ae31e9b8.js     235.78 KiB / gzip: 78.01 KiB

@menghany

This comment was marked as off-topic.

@aleclarson
Copy link
Member

For both 2.6 and 2.7, you're using the same version of @vitejs/plugin-react yes?
(want to make sure plugin-react is not the cause)

@Lani
Copy link
Author

Lani commented Dec 16, 2021

For both 2.6 and 2.7, you're using the same version of @vitejs/plugin-react yes? (want to make sure plugin-react is not the cause)

Yes, the same version, which resolved to 1.1.1, when I created this issue. I did not change the plugin-react version between the tests. Only targeted different versions of vite using npm i -D vite@2.6.14 and npm i -D vite@2.7.1.

We noticed the issue in our internal project at work. So, I created the example repository and could reproduce it there with the same results. As we mainly use Windows, we are now stuck on 2.6, as we switched to Vite from CRA because of the bad performance of CRA.

But as you can see the performance degration is also visible on Linux, but as the Linux file system, in my experience, is a lot faster at handling many small files request than Windows, the performance degration is not as big there, but still significant I would say.

Let me know if there is anything else I can do to help to track down the cause of this.

@aleclarson
Copy link
Member

You can try using --profile flag, which writes to ./vite-profile.cpuprofile once the dev server is ready. Then you can open that up in Chrome devtools to figure out where in Vite the slowdown appeared.

@Lani
Copy link
Author

Lani commented Dec 21, 2021

Hi @aleclarson!

I've now had time to run the profile traces, and from the first look at it, it looks like the main regression is in how often realPath is being called. Maybe it's related to this file: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/resolve.ts

I haven't had much more time to investigate the changes between 2.6.14 and 2.7.0 that calls realPath, but maybe someone with more experience with the code base could find it.

2.7 trace:
image

2.6 trace:
image

I've also attached the files:
vite-27-profile.zip
vite-26-profile.zip

@aleclarson
Copy link
Member

@Lani Thanks for investigating! You could try resolve.preserveSymlinks: true in your Vite config to see if that helps. I'll look into reducing the number of realpath calls. 👍

@Lani
Copy link
Author

Lani commented Dec 22, 2021

@aleclarson Thanks for the tip! Preserving symlinks doubled the speed! I now see dev startup times between 20-22 seconds. With this setting active 2.7 is only about 3 times slower than 2.6. That is still significant though, so if you manage to reduce the number of realpath calls to speed 2.7 up even more, that would be great 😃

Maybe it's possible to cache some of the calls?

@aleclarson
Copy link
Member

Maybe it's possible to cache some of the calls?

I spent a big part of my day yesterday writing exactly that. 😄

If you'd like, I could share the code with you to try locally and I'll submit a PR to Vite, but I'm trying to boost my GitHub sponsor count, so I'd like to ask if could first sponsor me for as little as $1 (or however much you value this fix). 🤞

Cheers 🍻

@Lani
Copy link
Author

Lani commented Dec 23, 2021

@aleclarson I'd be happy to try out the changes that you've made. I'm, however, going on vacation over the holidays, so it may be a couple of weeks before I can get to it.

We just started using Vite at work, at it's really great! We do not yet have a process in place for sponsoring open-source projects, but I'm advocating for it. I did, however, sponsor you personally with a onetime $10 donation. I think that the work is worth more than that, related to the hours that you've probably put into it. But hopefully it counts as something.

Merry Christmas! 🎅

@wuyongzhi

This comment was marked as spam.

@aleclarson
Copy link
Member

#6412 is ready for testing in big projects

@Lani Your donation is greatly appreciated! ❤️ Others impacted by this bug are also encouraged to sponsor me for $1 to help me boost my sponsor count. Even a small donation will help Vite more than you know, as I'm withholding a lot of improvements because I feel unappreciated around here.

@benatshippabo
Copy link
Contributor

#6412 is ready for testing in big projects

@Lani Your donation is greatly appreciated! ❤️ Others impacted by this bug are also encouraged to sponsor me for $1 to help me boost my sponsor count. Even a small donation will help Vite more than you know, as I'm withholding a lot of improvements because I feel unappreciated around here.

Also donated, love your work @aleclarson

@Lani
Copy link
Author

Lani commented Jan 10, 2022

@aleclarson I've tried to build vite to test this, but I get the following error:

/c/code/_github/vite/packages/vite (feat/realpath-cache)
$ pnpm build-bundle

> vite@2.8.0-beta.1 build-bundle C:\code\_github\vite\packages\vite
> rollup -c


C:\code\_github\vite\packages\vite\src\client\env.ts → dist\client\env.mjs...
created dist\client\env.mjs in 2s

C:\code\_github\vite\packages\vite\src\client\client.ts → dist\client\client.mjs...
created dist\client\client.mjs in 2.3s

C:\code\_github\vite\packages\vite\src\node\index.ts, C:\code\_github\vite\packages\vite\src\node\cli.ts → dist...
shimmed: plugins/terser.ts
shimmed: cac/dist/index.mjs
shimmed: fsevents-handler.js
shimmed: process-content.js
shimmed: lilconfig/dist/index.js
shimmed: import-from/index.js
(!) Plugin typescript: @rollup/plugin-typescript TS2304: Cannot find name 'cjsInclude'.
src\node\packages.ts: (124:9)

124     if (cjsInclude && pkgPath !== originalPkgPath) {
            ~~~~~~~~~~

src\node\packages.ts: (125:35)

125       const filter = createFilter(cjsInclude, undefined, { resolve: false })
                                      ~~~~~~~~~~

src\node\packages.ts: (127:9)

127         cjsInclude.push(path.dirname(pkgPath) + '/**')
            ~~~~~~~~~~

created dist in 28.3s

C:\code\_github\vite\node_modules\.pnpm\terser@5.10.0_acorn@8.7.0\node_modules\terser\dist\bundle.min.js → dist...
created dist in 1.3s

@aleclarson
Copy link
Member

@Lani whoops, I fixed that but pushed to the wrong branch, so try again :)

@Lani
Copy link
Author

Lani commented Jan 11, 2022

@aleclarson Thank you for the work you've put in! The PR helped some, but unfortunately it is still a big regression from 2.6. On Windows it now went from 6.2 times slower to 3.9 times slower:

2.6.14: 9, 9, 10, 9, 9 (re-ran to get current state of my environment)
2.7.1: 46, 47, 46, 47, 48
PR: 36, 38, 38, 36, 32
PR-SYM: 31, 26, 26, 27, 28 (preserveSymlinks = true)

With preserveSymlinks set to true it is, however, a little better, but still 3 times slower than 2.6.

Hopefully, there is something more that can be done? As the performance of 2.6 was what made us switch to vite. In a monorepo the dependencies often change, so full rebuilds happen often. With this change I wouldn't say that it is a dealbreaker, but still unfortunate that vite has gotten so much slower.

This is the cache hit metrics from the production build (I didn't figure out how to get them from the dev build):

vite v2.8.0-beta.1 building for production...
✓ 10762 modules transformed.
rendering chunks (2)...
cacheSize: 62
cacheHits: 724
fsCalls:   62

image

vite-PR1-profile.zip

@jonlepage

This comment has been minimized.

@jonlepage

This comment was marked as off-topic.

@benatshippabo

This comment was marked as off-topic.

@xiaolu6t
Copy link

Hot load is very slow in vite@2.8.4.

@sapphi-red
Copy link
Member

FYI the output result with my repository was as below.

cacheSize: 59
cacheHits: 173
fsCalls:   59

@rxliuli
Copy link
Contributor

rxliuli commented Mar 15, 2022

Had the same problem, the profile file is as follows, the current startup time has reached an astonishing 26994ms

vite-profile.zip

@aleclarson
Copy link
Member

aleclarson commented Mar 15, 2022

We know the problem arrived between v2.6.14 and v2.7.0, according to @Lani's report.

Can someone narrow the problem down to a specific beta version?

@rxliuli
Copy link
Contributor

rxliuli commented Mar 16, 2022

We know the problem arrived between v2.6.14 and v2.7.0, according to @Lani's report.

Can someone narrow the problem down to a specific beta version?

Do you mean to test and upload the profile file with the beta version?

Tested vite 2.9.0-beta.2 and it seems to solve the problem

27910ms => 5093ms

profile.zip

@aleclarson
Copy link
Member

aleclarson commented Mar 16, 2022

@rxliuli That's probably a result of 24bb3e4 (not 100% sure), but it's not a true fix, since dep optimization was added long before this regression was reported. To confirm my suspicion, you could test v2.9.0-beta.0 to see if it's not "fixed" there too.

I'm asking if someone can find which 2.7 beta version introduced this regression

@rxliuli
Copy link
Contributor

rxliuli commented Mar 17, 2022

@rxliuli That's probably a result of 24bb3e4 (not 100% sure), but it's not a true fix, since dep optimization was added long before this regression was reported. To confirm my suspicion, you could test v2.9.0-beta.0 to see if it's not "fixed" there too.

I'm asking if someone can find which 2.7 beta version introduced this regression

I tested it and basically determined that it was a bug introduced by 2.7.0-beta.5

test command

pnpm i && rm -rf node_modules/.vite/ && pnpm vite --profile --force
  • 2.7.0-beta.4: 9441ms
  • 2.7.0-beta.5: 18540ms

profile

vite-profile.zip

Even before the bug was introduced, the performance doesn't seem to be very good (9s+), is it possible to keep doing some optimizations to keep the fast performance of vite development?


I'm basically sure it's a performance issue with #5665 , the following is a performance comparison before and after including this pr

  • pull before: 8858ms
  • pull after: 29174ms

pull vite-profile.zip

@bluwy bluwy added the p4-important Violate documented behavior or significantly improves performance (priority) label Jun 26, 2022
@patak-dev patak-dev added the performance Performance related enhancement label Mar 10, 2023
@bluwy
Copy link
Member

bluwy commented Apr 1, 2023

We have been improving Vite's performance lately and I believe this has been fixed by the few PR references above. Closing this as the work has been completed. Appreciate if anyone following would give Vite 4.3 beta a spin too.

@bluwy bluwy closed this as completed Apr 1, 2023
@Lani
Copy link
Author

Lani commented Apr 5, 2023

@bluwy Just WOW! It builds under the second now! Really impressive work by the team! Thank you for all the effort that you have put into this.

@jonlepage
Copy link

jonlepage commented Apr 5, 2023

image
image

hum, i lost 1 ms

@github-actions github-actions bot locked and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p4-important Violate documented behavior or significantly improves performance (priority) performance Performance related enhancement
Projects
None yet
Development

No branches or pull requests