Improving my dev workflow - Save thy memory ⚡️


For my dev flow, I need to run a ring backend server, figwheel for frontend hot loading, and a datomic database. For the uninitiated, each of them is running on a different JVM and now add IntelliJ(curse me for not learning Emacs), a browser with a million tabs, Spotify, Slack, Zoom and there's no difference between a toaster and Macbook.
Although you can control the JVM memory usage, it's easy to run into memory issues and I'm yet to find a decent balance between performance and memory usage.
macOS extensively uses swap to address memory overflow but SSD's lifespan decreases with each write and more importantly, it's slower than RAM, which results in slower operations and workflows.


Reduce the memory allocation pool by tuning JVM with Xms option

Putting all things in a server

Get your code on a 20$ machine which gives you 2CPUs and 4 gigs of RAM. I found this enough and added more swap just in case. Setup your Nginx ssl and certificates if any and start the servers.

Connecting to remote machine

You don't want to swap local URLs with server URLs and run the whole process; there's something better i.e ssh port forwarding. Start port forwarding with this:
ssh -L port-local-1:localhost:remote-port-1 -L port-local-2:localhost:port-local-2 [email protected]
Every request to localhost:port-1 will forward to server's port-1

Syncing changes

Now for every change you make to your IntelliJ you want to see your changes hot loaded. All intelli-j products have file watchers. File watchers allow you to run a script when a file is saved, which is exactly what we need. Add a file watcher which rsync's your local codebase to remote. A couple of lines of bash
#!/usr/bin/env bash
cd ~/Documents
rsync -av proj/ [email protected]:~/a-folder --delete --exclude=exclude-folder/
And that's it.
Tip: Don't forget to forward your nrepl ports as well.
Although this is very specific to Clojure the key idea is to use an additional dedicated system for your computation and make it seem like your local machine is the dedicated machine.
Skip upgrading to an expensive macbook and get a cheap server(take advantage of promo credits😬)


Last modified 5mo ago
Copy link