Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

We Built a Tokio-Style Scheduler in a Theorem Prover (And It Beat Node.js)

Description and use

LeanIn, a multi‑threaded scheduler built in Lean 4, outperforms Node.js in benchmarks and offers formal verification of correctness.

Problem

Concurrency bugs in backend systems are hard to detect and can cause catastrophic failures under specific load spikes.

Outcome

LeanIn achieves higher throughput and lower P99 latency than Node.js while providing formal verification of scheduler correctness.

Workflow

  • 1. Identify concurrency challenges in backend workloads.
  • 2. Choose Lean 4 for its type‑system and native compilation.
  • 3. Encode scheduler state transitions in Lean’s type system to enable formal verification.
  • 4. Implement a multi‑threaded work‑stealing algorithm inspired by Rust’s Tokio.
  • 5. Apply Functional But In‑Place (FBIP) to enable destructive updates with reference counting.
  • 6. Compile Lean 4 code to native C and then to a binary.
  • 7. Benchmark LeanIn against Node.js across standard workloads.
  • 8. Publish the open‑source repository and benchmark results.

Evidence

Our LeanIn server actually outpaces Node.js across almost all standard performance benchmarks.

Source

Lean’s type system allows us to encode the actual state transitions of our scheduler. This means we can formally verify that tasks are never dropped, queues never deadlock, and memory is handled correctly.

Source

Lean 4 doesn’t run on a virtual machine. It compiles down to highly optimised C code, which is then compiled to a native binary.

Source

  • Record date: 2026-10-20T15:41:31.769Z