Why You Need sccache

As the main­tainer of a rea­son­ably pop­u­lar open source pro­ject writ­ten in Rust, I find my­self cloning PRs and swap­ping be­tween branches dozens of times a day. In do­ing so, I of­ten blow away Rust’s com­pi­la­tion cache ei­ther via git clean -xf . or by chang­ing de­pen­dency ver­sions.

Having a build cache that is sep­a­rate from the pro­ject is a huge win for com­pile times, which is why I use sccache.

For those un­aware, sccache is a build tool for C, C++ and Rust pro­jects that stands in front of the com­piler. If a given file’s hash is the same across calls to the com­piler, sccache reuses the pre­vi­ous re­sult. This cache is com­piler–and pro­ject ag­nos­tic. In my case, it sits in $HOME/.scccache, but you can set it up with AWS S3, Redis or a myr­iad of other op­tions.

If a de­pen­dency is cached from a com­pile in one pro­ject, it is avail­able for a build in an­other.

In short: you need sccache if you are fre­quently swap­ping be­tween branches with sim­i­lar (but not iden­ti­cal) de­pen­den­cies or ex­pect to fre­quently delete Rust’s disk cache.

Why You Don’t Need sccache

If you are work­ing in a sin­gle branch on a pro­ject whose de­pen­den­cies re­main some­what sta­ble, sccache might ac­tu­ally in­crease your com­pile time. Since sccache has to hit the disk (or even the net­work) re­gard­less of whether it is a cache hit, a lit­tle bit of la­tency is added. If you ex­pect most com­piles to be cache hits or most com­piles to be cache misses, sccache is no more use­ful than the built-in caching cargo pro­vides.

In that case you should not use sccache.

Wrap-Up

Regardless of whether you in­stall sccache on your ma­chine, it is a neat lit­tle tech­nol­ogy. I would rec­om­mend the cu­ri­ous reader take a look for them­selves. You might be in­spired.