Skip to content

perf: avoid expensive instance re-synthesis in cbv#14009

Draft
wkrozowski wants to merge 1 commit into
leanprover:masterfrom
wkrozowski:wojciech/fable_cbv_optimisations
Draft

perf: avoid expensive instance re-synthesis in cbv#14009
wkrozowski wants to merge 1 commit into
leanprover:masterfrom
wkrozowski:wojciech/fable_cbv_optimisations

Conversation

@wkrozowski

Copy link
Copy Markdown
Contributor

This PR is an experiment in using Fable in optimising cbv.

This PR speeds up the `cbv` and `decide_cbv` tactics by up to 2x on `Decidable` evaluation workloads and significantly reduces elaborator and kernel unfolding (visible in `diagnostics` counters). Previously, rewriting a proposition argument inside an instance term forced the congruence machinery to re-synthesize a `Decidable` instance for the entire remaining proposition at every step, making evaluation of bounded quantifier instances quadratic.

The `cbv` pre-pass now evaluates class-valued applications whose congruence theorem carries instance arguments directly via equations (`handleClassApp`), instead of first rewriting their arguments via congruence. `Decidable`-transport wrappers (`decidable_of_decidable_of_eq`, `decidable_of_decidable_of_iff`, `decidable_of_iff`, `decidable_of_iff'`) are evaluated by dedicated simprocs that evaluate the wrapped instance and rewrite the wrapper to `isTrue`/`isFalse` directly, justified by `Subsingleton (Decidable p)`. Instances that cannot be evaluated structurally (e.g. dependent matches over functions defined by well-founded recursion, which neither congruence nor kernel reduction can evaluate) fall back to deciding the underlying proposition (`handleStuckDecidable`). The `ite`/`dite`/`decide` control-flow simprocs additionally try synthesizing an instance for the rewritten condition when the original instance is stuck, preserving the previous behavior for opaque instances. On `tests/elab_bench/cbv_decide.lean`, evaluation time drops by ~1.8x and kernel-checking time of the produced proofs by ~1.6x.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wkrozowski wkrozowski added the changelog-language Language features and metaprograms label Jun 11, 2026
@wkrozowski

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-radar

leanprover-radar commented Jun 11, 2026

Copy link
Copy Markdown

Benchmark results for ddbe36b against efbd4b8 are in. There are significant results. @wkrozowski

  • 🟥 build//instructions: +2.3G (+0.02%)

Large changes (3✅)

  • elab/cbv_decide//instructions: -18.1G (-41.72%)
  • elab/cbv_decide//task-clock: -1s (-41.11%)
  • elab/cbv_decide//wall-clock: -1s (-41.33%)

Medium changes (1🟥)

  • 🟥 elab/cbv_leroy//instructions: +347.3M (+0.81%)

Small changes (2✅, 5🟥)

  • 🟥 build/module/Init.Sym.Lemmas//instructions: +34.8M (+1.82%)
  • 🟥 build/module/Lean.Meta.Tactic.Cbv.ControlFlow//instructions: +1.8G (+27.28%) (reduced significance based on *//lines)
  • 🟥 build/module/Lean.Meta.Tactic.Cbv.Main//instructions: +714.2M (+5.59%) (reduced significance based on *//lines)
  • 🟥 elab/cbv_divisors//instructions: +231.5M (+0.47%)
  • 🟥 elab/cbv_merge_sort//instructions: +99.5M (+0.56%)
  • mvcgen/sym/AddSubCancelDeep/100/vcgen//wall-clock: -11ms (-6.51%)
  • mvcgen/sym/GetThrowSet/600/kernel//wall-clock: -36ms (-7.95%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-language Language features and metaprograms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants