Tim Case
Joined
Activity
It turns out with Chokidar watching the app/javascript/*/ dir, I have a custom built html 5 web component library git submoduled at app/javascript/rayon. I didn't realize inside of that library was a directory of svg icons containing approximately 23,000 files. This was the cause of the massive RAM usage. I assume Chokidar was setting up to watch all of those files which is crazy. The solution of course is to pay careful attention to what is being watched by Chokidar and to exclude things like a 23,000 file SVG directory. Sorry for the confusion earlier I was thinking of the problem in terms of what was being imported by esbuild, and that was wrong so to be clear:
- Live Reload with Esbuild in Rails is perfectly fine.
- Esbuild is also perfectly fine.
- Chokidar is also perfectly fine.
- Starting Esbuild with live reload actually consumes very little RAM normally.
- Any massive CPU usage and RAM spiking when starting up the Rails app locally (./bin/dev) might be an indicator that Chokidar is watching a directory with massive amount of files.
Sorry for the confusion.
Hey I need to walk back what I said about esbuild being the issue, the truth is I'm not sure what the issue is exactly. The only thing I can say is that a memory issue does happen with happen at times when starting an app, and if memory serves it's from loading a certain type of npm package. I went deep down the rabbit hole to figure out the issue and never was able to discern what it was exactly. This weekend I'm gonna try to see if I can't reproduce the issue and get a project up to show it. Apologies for my earlier message I'm realizing I don't have enough confidence to proclaim what the issue is. It was really confusing.
I found the downside with this approach is that if you include certain npm packages it will cause a problem with esbuild that results in some insane memory usage. You'll fly through 10s of gigs of ram just starting your app in local dev. It's a problem that esbuild acknowledges and probably won't go away.
I found this gem that I think is pretty damn awesome: https://github.com/railsjazz/rails_live_reload. It gets me what I want for live reload. For esbuild I still use it but just with a watch flag.