Skip to content

fix: add checkSystem to LCNF simp#13231

Closed
nomeata wants to merge 2 commits intomasterfrom
joachim/lcnf-simp-checkSystem
Closed

fix: add checkSystem to LCNF simp#13231
nomeata wants to merge 2 commits intomasterfrom
joachim/lcnf-simp-checkSystem

Conversation

@nomeata
Copy link
Copy Markdown
Collaborator

@nomeata nomeata commented Apr 1, 2026

This PR adds a checkSystem call to the LCNF simplifier's recursive
traversal. This breaks up multi-second gaps (observed up to 1.75s on
big_do.lean) that prevent prompt cancellation in the IDE.

Local benchmarks on big_do and simp_local show no measurable
wall-clock regression with unconditional checking (no amortization
needed).

Found using LEAN_CHECK_SYSTEM_INTERVAL_MS monitoring from #13218.

This PR adds a periodic `checkSystem` call to the LCNF simplifier's
recursive traversal, checking every 512 visited nodes. This breaks up
multi-second gaps (observed up to 2.3s on `big_do.lean`) without
measurable performance regression — the amortized cost is effectively
zero on benchmarks like `big_do` and `simp_local`.

An unconditional `checkSystem` on every node caused a 0.4% instruction
count regression, which is why the amortized approach is used instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nomeata nomeata added the changelog-compiler Compiler, runtime, and FFI label Apr 1, 2026
@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented Apr 1, 2026

!radar

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Apr 1, 2026

Benchmark results for ce6b715 against 978bde4 are in. There are no significant changes. @nomeata

  • 🟥 build//instructions: +3.5G (+0.03%)

Small changes (2🟥)

  • 🟥 build/module/Lean.Compiler.LCNF.Simp.Main//instructions: +146.5M (+2.55%) (reduced significance based on *//lines)
  • 🟥 elab/big_do//instructions: +35.7M (+0.15%)

@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented Apr 1, 2026

Ok, this looks cheap enough.

@nomeata nomeata added this pull request to the merge queue Apr 1, 2026
@nomeata nomeata removed this pull request from the merge queue due to a manual request Apr 1, 2026
@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented Apr 1, 2026

(Taking this off the queue, measurement since shows that 512 may be too rare to get latency into the 50ms area)

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Apr 1, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

mathlib-lean-pr-testing bot commented Apr 1, 2026

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 978bde4a0f9d260b245e3c131b9202897d896c7b --onto fc0cf68539ad3b481a1802414c22c44506519c9d. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-01 14:32:53)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 3c6ea49d0e4ff3a924452809ca5aeb41b0611bef --onto fc0cf68539ad3b481a1802414c22c44506519c9d. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-04 07:50:05)
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-04-04 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-04 20:39:12)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

leanprover-bot commented Apr 1, 2026

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 978bde4a0f9d260b245e3c131b9202897d896c7b --onto cfa8c5a036d6990635c6ec50b02d0e806995cec3. You can force reference manual CI using the force-manual-ci label. (2026-04-01 14:32:55)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 978bde4a0f9d260b245e3c131b9202897d896c7b --onto 861bc19e0c1c45b5766cc5c9ef0488568368b236. You can force reference manual CI using the force-manual-ci label. (2026-04-03 21:26:29)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 3c6ea49d0e4ff3a924452809ca5aeb41b0611bef --onto 861bc19e0c1c45b5766cc5c9ef0488568368b236. You can force reference manual CI using the force-manual-ci label. (2026-04-04 07:50:06)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-04-04 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-04-04 20:39:13)

@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented Apr 3, 2026

Looks like my other changes made this one obsolete.

@nomeata nomeata closed this Apr 3, 2026
@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented Apr 3, 2026

Wrong, may still be needed.

@nomeata nomeata reopened this Apr 3, 2026
@nomeata nomeata marked this pull request as draft April 3, 2026 20:27
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented Apr 4, 2026

!radar

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Apr 4, 2026

Benchmark results for 65f5fbf against 3c6ea49 are in. Significant changes detected! @nomeata

  • 🟥 build//instructions: +15.5G (+0.13%)

Medium changes (1🟥)

  • 🟥 elab/big_do//instructions: +104.4M (+0.44%)

Small changes (66🟥)

Too many entries to display here. View the full report on radar instead.

@nomeata nomeata changed the title fix: add amortized checkSystem to LCNF simp fix: add checkSystem to LCNF simp Apr 4, 2026
@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented Apr 4, 2026

Closing: this PR is no longer needed after #13258 landed on master.

#13258 adds checkInterrupted to Core.withIncRecDepth, which covers the LCNF simp path — the sub-operations within simp (normExpr, normLetDecl, betaReduce, etc.) make CoreM calls that go through Core.withIncRecDepth and get checkInterrupted there.

Verified with a clean build from scratch: zero gaps at 50ms threshold across all 46 elab_bench tests and all previously problematic files (4595_slowdown, simp_local, big_do, aStructPerfIssue, cbv_iter) without any LCNF simp checkSystem.

@nomeata nomeata closed this Apr 4, 2026
@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented Apr 4, 2026

Reopening — the gap testing was incorrectly run on a branch without the monitoring instrumentation, so the zero-gap results were meaningless. Need to re-verify.

@nomeata nomeata reopened this Apr 4, 2026
@nomeata
Copy link
Copy Markdown
Collaborator Author

nomeata commented Apr 4, 2026

Closing: this PR is no longer needed after #13258 landed on master.

Verified with a clean build on the instrumented branch (joachim/checkSystemTime) which has LEAN_CHECK_SYSTEM_INTERVAL_MS monitoring in both C++ check_system and Lean checkInterrupted. Key findings:

No LCNF simp gaps at any threshold. Core.withIncRecDepth (#13258) calls checkInterrupted, which covers all CoreM sub-operations called within LCNF simp (normExpr, normLetDecl, betaReduce, etc.). The LCNF simp custom withIncRecDepth (SimpM.lean:146) doesn't call checkInterrupted itself, but it doesn't need to — the sub-operations it calls do.

Previously problematic files — zero gaps at 50ms:

Remaining gaps (elab_bench at 50ms) are all outside LCNF simp:

  • "type checker" — kernel/sharecommon gaps (up to 3.6s on cbv tests)
  • "interpreter" — Lean interpreter gaps
  • "Lean elaborator" — elaboration paths not covered by withIncRecDepth

None of these would be helped by adding checkSystem to LCNF simp.

@nomeata nomeata closed this Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-compiler Compiler, runtime, and FFI toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants