wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.49k stars 1.23k forks source link

Update Troubleshoot docs for Wails + Vite | Vite leaks memory in Windows #3903

Open nich-frai opened 3 days ago

nich-frai commented 3 days ago

Is your feature request related to a problem? Please describe.

While developing Wails using Vite as a frontend dev server there's a memory leak / continuous CPU usage because of constant rescans of "./wailsjs/" folder;

Don't know if it's something related to Windows platform but in 10 mins ~ the app took 4gb of memory and if left overnight it took the whole 64gb of avaliable RAM; There's a simple solution for it, since the Wails CLI will recompile / relaunch when a dependency from go is changes just add the "wailsjs" folder to the watcher exclude setting in vite;

Describe the solution you'd like

Add as part of the Troubleshooting section the following "vite.config.ts" update:

export default defineConfig({
  // ...
  server: {
    watch: {
      ignored: ["**/wailsjs/**"]
    }
  },
});

This prevents the leak / constant rescan of the folder by Vite;

Describe alternatives you've considered

Launching Vite by itself (no Wails dev) will NOT reproduce it! The interaction of Wails + Vite managing/watching the same directory will cause this!

Additional context

I'm using windows, so the problem mught be related to the FS Watcher in this system especifically; Will try to reproduce in Linux to see if it still occurs and post here!

It caused me to lose a day or so finding WHY was it leaking to the point I was accepting having to restart the proccess from time to time, so I thought it might save someone else's sanity posting the cause / solution of this specific problem.

leaanthony commented 3 days ago

Thanks for reporting this. I suspect it's nothing to do with that specific file per se but more to do with the fact that it's getting regenerated and the watcher isn't cleaning up old file handles. You could try upgrading the underlying notify library and see if that fixes it.