/Clojure-CLI-CRaC

Faster Clojure Startup with Checkpoint/Restore

Primary LanguageShellEclipse Public License 1.0EPL-1.0

Clojure-CLI-CRaC

A drop-in Clojure-CLI replacement that gets you to the REPL fast.

Clojure is known for its slow start. This project utilizes Linux's Checkpoint/Restore functionality to cache JVM state to disk after Clojure finishes initialization. Subsequent Clojure launches are much faster by restoring from the cached state.

Read more about the design process: part 1 part 2.

Installation

Clojure-CLI-CRaC requires bash and rlwrap. It can be used alongside the offical Clojure CLI.

  1. Clone this repo
git clone https://github.com/YizhePKU/Clojure-CLI-CRaC.git
  1. Download the latest build of JDK with CRaC. Unpack with sudo (sudo is necessary because it contains a setuid executable for triggering Checkpoint/Restore)
wget https://github.com/CRaC/openjdk-builds/releases/download/17-crac%2B5/openjdk-17-crac+5_linux-x64.tar.gz
sudo tar xf openjdk-17-crac+5_linux-x64.tar.gz
  1. Move the unpacked directory into this repo. Rename it to openjdk-17-crac
sudo mv openjdk-17-crac+5_linux-x64 Clojure-CLI-CRaC/openjdk-17-crac
  1. (Optional) add the bin/ directory to your PATH

Usage

Clojure-CLI-CRaC is a drop-in Clojure CLI replacement. Run clojure and clj as you normally would.

  • JVM options can only be set on the first launch (otherwise they have no effect)
  • Will automatically invalidate the checkpoint when deps.edn changes (e.g. new dependencies)

Limitations and known issues

  • Currently Linux-x86_64 only
  • Will print a bunch of nonsense when creating a checkpoint
  • There's currently an upstream bug that causes whitespace in command line arguments to be misinterpreted