Crystal compiler utilizes 500MB~ ram after compiling is complete

I mentioned this in gitter last week or so, but I think the lead devs should be aware of it. I don’t think it’s normal behavior (might be a bug).

When executing crystal app.cr, the memory usage will shoot up about 500MB of ram (normal because the compiler uses it), but then after your app has started, that memory is still allocated. In fact, all the processes of the compiler are still running

I’m trying to find a workaround where we can compile our Crystal app, then execute it without the compiler still running.

I’ve got a MasterServer.cr that eats up around 500MB, then my GameServer that eats up another 500MB while only having 8GB of total ram.

My GameServer and MasterServer apps only utilize several MBs of ram when executed without the compiler in the background. This is how it should be after the compiler has finished, right?

I was thinking of something like

crystal build src/GameServer.cr --release && ./GameServer

But don’t know how to cancel the compiler processes through commands cause it has a list of PIDs

I’ve tested this on native Debian 9, and WSL’s Ubuntu

Screenshots

  • no compiler in the background:

  • compiler processes still in background:

edit: Or, maybe a compiler flag that automatically kills all the compiler processes after compilation is done? Not sure, just thinking out loud

crystal build src/GameServer.cr --release && ./GameServer
Is the way to go, once the build ends the memory used by the compiler will be freed and your gameserver can run by itself.

1 Like

Wow, that’s weird. Yesterday when I tried that command, htop kept showing the lingering compiler processes. Now, when I use top those compiler processes are no longer there and it seems to work. Wtf

Yeah I’ve noticed that before too. It doesn’t exec the new process but just runs it “in case you have a flag set to output debug info” (i.e. statistics on how long it took to run). It surprised me. Maybe it should exec if that flag isn’t set hmm… :)