Rust Scripts That Start in 5ms

I’ve fallen in love with Rust scripts. With cargo -Zscript, you get type safety, the entire crates ecosystem, and performance that embarrasses Python. The front-matter syntax is perfect—dependencies right at the top, no separate Cargo.toml needed.

But the startup time was killing me. 200ms minimum, even when nothing changed. For scripts you run constantly, that’s death by a thousand paper cuts.

So I built scriptr: a wrapper that makes Rust scripts start as fast as shell scripts.

The trick is smart caching. First run builds normally through cargo. After that, we check the file’s modification time. If unchanged, exec the cached binary in 5ms flat. If the file was touched (say, by git), we check the content hash. Only if the content actually changed do we rebuild.

This isn’t rocket science. It’s just fixing an annoying problem that was keeping me from using Rust for everything.

Now my git helpers start instantly. My build scripts feel snappy. My daily automation doesn’t lag. Rust has become a genuinely great scripting language.

The future of scripting is typed, fast, and starts in 5ms.

cargo install scriptr
chmod +x hello.rs
./hello.rs  # First run: ~1s
./hello.rs  # Every run after: 5ms

Try it. You’ll never go back to slow scripts.

Context

The Problem

Every cargo script invocation:

  • Checks the entire dependency graph
  • Verifies all fingerprints
  • Walks directory trees
  • = 200ms minimum overhead

Python starts in 20ms. Shell scripts in 5ms.

The Solution

scriptr: A transparent wrapper that caches builds.

#!/usr/bin/env scriptr
---
[dependencies]
clap = { version = "4.5", features = ["derive"] }
---

use clap::Parser;

fn main() {
    println!("Hello, fast!");
}

First run: Normal build time
Subsequent runs: 5ms

TL;DR

Two-level caching:

  1. Check mtime → unchanged? → exec cached binary
  2. File touched? → check BLAKE3 hash → same? → exec cached binary
  3. Actually changed? → rebuild

Result: 34x speedup for cached runs.

Performance

M2 MacBook Pro measurements:

Hello World:

  • cargo -Zscript: 157ms every time
  • scriptr: 157ms → 4.6ms

With clap dependency:

  • cargo -Zscript: 157ms every time
  • scriptr: 190ms → 4.8ms

Install

cargo install scriptr

I’ve fallen in love with Rust scripts. With cargo -Zscript, you get type safety, the entire crates ecosystem, and performance that embarrasses Python. The front-matter syntax is perfect—dependencies right at the top, no separate Cargo.toml needed.

But the startup time was killing me. 200ms minimum, even when nothing changed. For scripts you run constantly, that’s death by a thousand paper cuts.

So I built scriptr: a wrapper that makes Rust scripts start as fast as shell scripts.

The trick is smart caching. First run builds normally through cargo. After that, we check the file’s modification time. If unchanged, exec the cached binary in 5ms flat. If the file was touched (say, by git), we check the content hash. Only if the content actually changed do we rebuild.

This isn’t rocket science. It’s just fixing an annoying problem that was keeping me from using Rust for everything.

Now my git helpers start instantly. My build scripts feel snappy. My daily automation doesn’t lag. Rust has become a genuinely great scripting language.

The future of scripting is typed, fast, and starts in 5ms.

cargo install scriptr
chmod +x hello.rs
./hello.rs  # First run: ~1s
./hello.rs  # Every run after: 5ms

Try it. You’ll never go back to slow scripts.