vitejs / vite-plugin-react-swc

Speed up your Vite dev server with SWC
MIT License
834 stars 54 forks source link

`vite-plugin-react-swc` makes vite build 33% slower than `vite-plugin-react` #43

Closed hanayashiki closed 1 year ago

hanayashiki commented 1 year ago

My closed-source application is about 100000 lines of TypeScript, as tokei counts:

===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 CSS                     2           44           38            0            6
 Dockerfile              1           28           19            0            9
 HTML                    1           47           40            0            7
 JavaScript              7          319          299            4           16
 JSON                    4          252          244            0            8
 SVG                   141         1348         1346            0            2
 TSX                   410        75480        69073          182         6225
 TypeScript            527        37038        33600          185         3253
 XML                     1            9            9            0            0
-------------------------------------------------------------------------------
 Markdown                4          463            0          287          176
 |- Shell                1            5            4            1            0
 |- TypeScript           1           38           29            2            7
 (Total)                            506           33          290          183
===============================================================================
 Total                1098       115028       104668          658         9702
===============================================================================

My plugin configuration:

react({ tsDecorators: true })

When switching to react-swc@3.1.0-beta.2, the vite build commands consumes 40s, compared to react@3.0.1 in 32s.

I'm sorry I am unable to open-source my business application, but could there be any benchmark showing react-swc is actually faster than react? There's no doubt that swc does faster in transpiling, but the cost of communication between native and javascript could be the bottleneck.

I also notice that this plugin sets esbuild: false in top-level config, could the fact that swc is slower than esbuild in transpiling lead to slower build?

ArnaudBarre commented 1 year ago

For both, if you don't use transpiler (Babel/SWC) plugins (at least true for SWC in your case), you are using only esbuild during build time. So I expect to have almost no difference for build time. Are you using the same tsconfig/vite core version in both tests? Maybe this could be a speed regression from Vite core or esbuild.

If everything else is strictly identical that's strange. You can use vite build --profile. If you're ok with sharing the name of your files, you can send it to me by email.

The main goal of this plugin is to speed up dev performances, the time for the app to load for vite dev should be noticeably faster

ArnaudBarre commented 1 year ago

Hi! Do you have more information on this? Do you still noticed a difference on a 3 runs average?