leanprover / leanprover/lean4

Very high CPU usage when making any edits at the top of a file

Open
#15,013 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
Description

When editing at the top of any long Lean file, CPU usage spikes a lot. This is presumbly caused by re-elaborating the entire file on every keystroke. It can be mitigated by placing #exit after the block being edited, but this is very inconvenient.

Context

I use Lean on a laptop, and if my laptop starts to get hot, the keyboard becomes too hot to type on. So this bug makes writing Lean somewhat inconvenient for me – I always have to use #exit whenever I make changes at the top of any file. This is possibly editor-specific, but it also produces input lag, which is annoying.

Steps to Reproduce
  1. lake new Reproducer
  2. In Reproducer.lean, repeat the line example : Nat := 5 a thousand or so times
  3. Start writing a comment at the top of the file
  4. Observe your computer fans start to whir, and CPU usage to spike
  5. Place #exit after the comment, and continue writing the comment
  6. Observe that CPU usage no longer spikes

Expected behavior: I can edit the top of the file without my laptop getting too hot and without having to use #exit.

Actual behavior: CPU usage is very high.

Versions

Lean 4.35.0-nightly-2026-09-03
Target: x86_64-unknown-linux-gnu Linux

Reproduced in both Neovim and VSCode.

Additional Information

A screen recording of the issue. Notice the CPU usage goes from 250% to 6% with #exit.

https://github.com/user-attachments/assets/d82bb307-547d-48e1-8ec4-5ee9e3c0acb7

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the minimal lake new Reproducer case: repeat example : Nat := 5 about a thousand times, then edit at the top with and without #exit. Trace the work triggered by those edits in both Neovim and VSCode; done means top-of-file editing no longer causes very high CPU usage or input lag without requiring #exit.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, developer-experience, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.