{
  "id": 34180,
  "title": "Taming a 40-Minute Lean CI: Three Rounds, Three Wrong Suspects",
  "url": "https://urgent.news/2026/08/02/taming-a-40-minute-lean-ci-three-rounds-three-wrong-suspects",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-02T07:06:16.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/iroha1203/taming-a-40-minute-lean-ci-three-rounds-three-wrong-suspects-7ke"
  },
  "original_language": "en",
  "account": "Our Lean 4 + mathlib project used to take 41 minutes for every single PR in CI. Now, the worst-case scenario of rebuilding the heaviest files from scratch takes 12 minutes, while an ordinary PR finishes in just a few minutes with incremental building. The improvements came through three rounds, each following a similar structure: problem, hypothesis, verification, and fix.\n\nSpoiler alert: all three times, the first hypothesis – the cause our intuition pointed to – turned out to be incorrect. The main solution lies in profiling, which systematically dismissed our hypotheses. To understand this story, you don't need to know Lean; I'll explain the key concepts as they come up. Most of the measurements and implementations came from AI agents, with my involvement mainly in approving numeric targets and accepting the results.\n\nBackground: The project involves AlgebraicArchitectureTheoryV2, a formal verification of a software architecture theory using Lean 4. The project relies on five key components: Term (a proof assistant), mathlib (Lean's extensive mathematics library), Lean's build tool (similar to cargo for Rust or npm for JS), Lean's build process (per-file elaboration emitting .olean artifacts), and the kernel axiom audit, which ensures every theorem is genuinely proved.\n\nRound 1: The axiom audit, 7m 11s → 11s\nProblem: Every theorem in Lean is derived from axioms and checked by the kernel (a trusted checker). However, Lean has an escape hatch called 'sorry' that allows users to plug in unproven propositions as axioms. To ensure every declaration is proved, the project runs an axiom audit for each declaration, checking that the set of axioms it reaches stays within three standard axioms.\n\nHypothesis: The audit's slow performance was due to a single giant file containing 5,000+ lines of audited declarations. Splitting this file should improve performance.\n\nVerification: We measured where the time was spent. Contrary to our hypothesis, the time was not spent on the big file itself. It was primarily due to how the audit was called – the collectAxioms function performed the dependency graph walk from scratch for every declaration, even though they shared the same foundation (mathlib). This resulted in O(declarations × graph) complexity, making the audit slower than the build process.\n\nFix: We implemented a two-phase approach. The success path involved sharing a visited set across all declarations, allowing the graph to be traversed only once. If a non-standard axiom was found, we would fall back to the classic per-declaration walk to attribute responsibility.",
  "summary": "Our Lean 4 + mathlib project used to spend 41 minutes in CI on every single PR. Today, the worst case — rebuilding the heaviest files from scratch — takes 12 minutes, and an ordinary PR finishes in a few minutes on an incremental build. What we fixed Before After Kernel axiom audit 7m 11s 11s An ordinary PR 41m (full rebuild, always) a few minutes (incremental) Worst case (heaviest files fully…",
  "key_points": [
    "Project's Lean 4 + mathlib CI took 41 minutes per PR",
    "Three rounds of profiling each disproved initial hypotheses",
    "Profiling revealed inefficiencies in axiom audit process"
  ],
  "editors_take": null,
  "illustration": "https://urgent.news/ill/34180.png",
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}