2 minutes
Speed up compilation times by exhausting RAM
Scenario:
- You have plenty of free RAM on your system
- You are compiling some relevant size project
- Your disk is slow (or even worst is on a network share)
- You change 1 line at time and recompile every 30 seconds
- You will soon get tired to take coffee breaks because “it’s compiling”

ccache
ccache is a nice utility that cache GCC (and others compilers) temporary files.
Just install it through your favorite package manager and prepend your gcc command with ccache.
If you use cMake, you can use set -DCMAKE_CXX_COMPILER_LAUNCHER=ccache.
Even more performance!
Move the ccache folder to your RAM:
echo "max_size = 5.0G" >> ~/.ccache/ccache.conf
echo "/tmp/ccache" >> ~/.ccache/ccache.conf
Even more RAM: everything ephemeral!
Are you crazy enough? Move your build folder to RAM!
With the script below you’ll:
- Mount a RAM filesystem (so, volatile) in the local
fastbuildfolder - Sync the content of
fastbuild_syncto this folder - Every 3 minutes, “backup”
fastbuildtofastbuild_sync
#!/bin/bash
# (C) 2022 Massimo Girondi - CC BY-NC-SA 4.0
# Mount a local folder and sync it periodically
LOCAL_DIR=fastbuild
LOCAL_DIR_SYNC=fastbuild_sync
SIZE=8G
TIME=3m
mkdir -p $LOCAL_DIR $LOCAL_DIR_SYNC
sudo mount -t tmpfs -o size=$SIZE tmpfs $LOCAL_DIR
# Sync curent build folder
sudo rsync -arv $LOCAL_DIR_SYNC/ $LOCAL_DIR/
while true; do
sleep $TIME
sudo rsync -arv $LOCAL_DIR/ $LOCAL_DIR_SYNC/
done
sudo umount $LOCAL_FOLDER
You should of course adapt SIZE to your ram.
And you’ll soon discover that you need to install more RAM!