Skip to content

perf: fix quadratic scaling in unused variable linter#12843

Closed
nomeata wants to merge 1 commit intomasterfrom
joachim/bench-linter-fix
Closed

perf: fix quadratic scaling in unused variable linter#12843
nomeata wants to merge 1 commit intomasterfrom
joachim/bench-linter-fix

Conversation

@nomeata
Copy link
Collaborator

@nomeata nomeata commented Mar 9, 2026

This PR fixes a quadratic performance issue in the unused variable linter
that was exposed by a benchmark with many implicit parameters from
https://github.com/JacquesCarette/BenchmarkingProofAssistants. The linter
previously called findStack? once per variable definition, resulting in
O(n·m) cost for n unused variables in a syntax tree with m leaves. This is
replaced by a single batch traversal (findStacks) that collects all
syntax stacks at once. Additionally, macro expansion info tree traversal
is now skipped entirely when no macro expansions are present.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

This PR fixes a quadratic performance issue in the unused variable linter
that was exposed by a benchmark with many implicit parameters from
https://github.com/JacquesCarette/BenchmarkingProofAssistants. The linter
previously called `findStack?` once per variable definition, resulting in
O(n·m) cost for n unused variables in a syntax tree with m leaves. This is
replaced by a single batch traversal (`findStacks`) that collects all
syntax stacks at once. Additionally, macro expansion info tree traversal
is now skipped entirely when no macro expansions are present.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nomeata nomeata added the changelog-language Language features and metaprograms label Mar 9, 2026
@nomeata
Copy link
Collaborator Author

nomeata commented Mar 9, 2026

!radar

@leanprover-radar
Copy link

leanprover-radar commented Mar 9, 2026

Benchmark results for f9aeed3 against 333ab1c are in! @nomeata

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

Small changes (44🟥)

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

@nomeata
Copy link
Collaborator Author

nomeata commented Mar 9, 2026

Overall a mild regression, and the problem this fixes (many unused implicit variables or something) is likely not relevant in practice. Closing until something shows it is.

@nomeata nomeata closed this Mar 9, 2026
@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 Mar 9, 2026
@leanprover-bot
Copy link
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-03-05 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-03-09 09:35:39)

mathlib-nightly-testing bot pushed a commit to leanprover-community/batteries that referenced this pull request Mar 9, 2026
@github-actions github-actions bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Mar 9, 2026
mathlib-nightly-testing bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Mar 9, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Mar 9, 2026
@mathlib-lean-pr-testing
Copy link

Mathlib CI status (docs):

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

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-language Language features and metaprograms mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN 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