cargo check for faster checking

Minimum Rust version: 1.16

cargo check is a new subcommand that should speed up the developmentworkflow in many cases.

What does it do? Let's take a step back and talk about how rustc compilesyour code. Compilation has many "passes", that is, there are many distinctsteps that the compiler takes on the road from your source code to producingthe final binary. However, you can think of this process in two big steps:first, rustc does all of its safety checks, makes sure your syntax iscorrect, all that stuff. Second, once it's satisfied that everything is inorder, it produces the actual binary code that you end up executing.

It turns out that that second step takes a lot of time. And most of the time,it's not neccesary. That is, when you're working on some Rust code, manydevelopers will get into a workflow like this:

  • Write some code.
  • Run cargo build to make sure it compiles.
  • Repeat 1-2 as needed.
  • Run cargo test to make sure your tests pass.
  • Try the binary yourself
  • GOTO 1.In step two, you never actually run your code. You're looking for feedbackfrom the compiler, not to actually run the binary. cargo check supportsexactly this use-case: it runs all of the compiler's checks, but doesn'tproduce the final binary. To use it:
  1. $ cargo check

where you may normally cargo build. The workflow now looks like:

  • Write some code.
  • Run cargo check to make sure it compiles.
  • Repeat 1-2 as needed.
  • Run cargo test to make sure your tests pass.
  • Run cargo build to build a binary and try it yourself
  • GOTO 1.So how much speedup do you actually get? Like most performance relatedquestions, the answer is "it depends." Here are some very un-scientificbenchmarks at the time of writing.
use casebuild performancecheck performancespeedup
initial compile11s5.6s1.96x
second compile (no changes)3s1.9s1.57x
third compile with small change5.8s3s1.93x