Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: simp_arith: faster denote through Lean.RArray #6068

Merged
merged 3 commits into from
Nov 14, 2024
Merged

Conversation

nomeata
Copy link
Collaborator

@nomeata nomeata commented Nov 13, 2024

This PR improves the asymptotic performance of simp_arith when there are many variables to consider.

On our synthetic benchmark:

simp_arith1               instructions    -25.1% (-4892.6 σ)

No effect on mathlib, though, guess it’s not used much on large goals there:
http://speed.lean-fro.org/mathlib4/compare/873b982b-2038-462a-9b68-0c0fc457f90d/to/56e66691-2f1f-4947-a922-37b80680315d

@nomeata
Copy link
Collaborator Author

nomeata commented Nov 13, 2024

!bench

@github-actions github-actions bot added the changes-stage0 Contains stage0 changes, merge manually using rebase label Nov 13, 2024
@nomeata nomeata changed the title refactor: simp_arith: faster denote through RArrray perf: simp_arith: faster denote through RArrray Nov 13, 2024
@nomeata nomeata changed the title perf: simp_arith: faster denote through RArrray perf: simp_arith: faster denote through Lean.RArray Nov 13, 2024
@nomeata nomeata changed the title perf: simp_arith: faster denote through Lean.RArray perf: simp_arith: faster denote through Lean.RArray Nov 13, 2024
@leanprover-bot
Copy link
Collaborator

Here are the benchmark results for commit 90138d8.
There were significant changes against commit 4e48ba9:

  Benchmark                 Metric          Change
  ============================================================
- big_omega.lean            branch-misses     1.4%    (14.8 σ)
- language server startup   branches          1.0%    (26.4 σ)
- language server startup   instructions      1.0%    (23.0 σ)
+ simp_arith1               branches        -23.9% (-3750.6 σ)
+ simp_arith1               instructions    -25.1% (-4892.6 σ)
- unionfind                 task-clock       11.0%    (10.8 σ)
- unionfind                 wall-clock       11.0%    (10.8 σ)

@nomeata nomeata mentioned this pull request Nov 13, 2024
@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 Nov 13, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Nov 13, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 13, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc November 13, 2024 16:01 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Nov 13, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 13, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Nov 13, 2024

Mathlib CI status (docs):

  • 🟡 Mathlib branch lean-pr-testing-6068 build against this PR was cancelled. (2024-11-13 16:06:01) View Log
  • ✅ Mathlib branch lean-pr-testing-6068 has successfully built against this PR. (2024-11-13 16:41:32) View Log
  • ✅ Mathlib branch lean-pr-testing-6068 has successfully built against this PR. (2024-11-13 22:17:51) View Log
  • ✅ Mathlib branch lean-pr-testing-6068 has successfully built against this PR. (2024-11-14 00:31:25) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 85f25967ea4e7650e7edf877777dcce3b6571795 --onto 1315266dd3faeaf28d1263668cb88f2f3f5e530c. (2024-11-14 12:44:36)

@leanprover-community-bot leanprover-community-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Nov 13, 2024
@nomeata nomeata changed the base branch from joachim/Poly.norm to nightly-with-mathlib November 13, 2024 20:46
@nomeata nomeata closed this Nov 13, 2024
@nomeata nomeata reopened this Nov 13, 2024
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc November 13, 2024 21:21 Inactive
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Nov 13, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 13, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 14, 2024
This PR adds the Lean.RArray data structure.

This data structure is equivalent to `Fin n → α` or `Array α`, but
optimized for a fast kernel-reduction `get` operation.

It is not suitable as a general-purpose data structure. The primary
intended use case is the “denote” function of a typical proof by
reflection proof, where only the `get` operation is necessary, and where
using `List.get` unnecessarily slows down proofs with more than a
hand-full of atomic expressions.


There is no well-formedness invariant attached to this data structure,
to keep it concise; it's semantics is given through `RArray.get`. In
that way one can also view an `RArray` as a decision tree implementing
`Nat → α`.

In #6068 this data structure is used in `simp_arith`.
nomeata added a commit that referenced this pull request Nov 14, 2024
This PR prepares #6068 by using the `RArray` data structure in
`simp_arith` the simp-arith meta code.

After the subsequent stage0 we can change the simp-arith theorems in
`Init`.
nomeata added a commit that referenced this pull request Nov 14, 2024
This PR makes `simp_arith` use `RArray` for the context of the
reflection proofs, which scales better when there are many variables.
@nomeata nomeata added the release-ci Enable all CI checks for a PR, like is done for releases label Nov 14, 2024
@nomeata nomeata changed the base branch from nightly-with-mathlib to master November 14, 2024 11:30
nomeata added a commit that referenced this pull request Nov 14, 2024
This PR makes `simp_arith` use `RArray` for the context of the
reflection proofs, which scales better when there are many variables.

On our synthetic benchmark:
```
simp_arith1               instructions    -25.1% (-4892.6 σ)
```

No effect on mathlib, though, guess it’s not used much on large goals there:
http://speed.lean-fro.org/mathlib4/compare/873b982b-2038-462a-9b68-0c0fc457f90d/to/56e66691-2f1f-4947-a922-37b80680315d
This PR prepares #6068 by using the `RArray` data structure in
`simp_arith` the simp-arith meta code.

After the subsequent stage0 we can change the simp-arith theorems in
`Init`.
This PR makes `simp_arith` use `RArray` for the context of the
reflection proofs, which scales better when there are many variables.

On our synthetic benchmark:
```
simp_arith1               instructions    -25.1% (-4892.6 σ)
```

No effect on mathlib, though, guess it’s not used much on large goals there:
http://speed.lean-fro.org/mathlib4/compare/873b982b-2038-462a-9b68-0c0fc457f90d/to/56e66691-2f1f-4947-a922-37b80680315d
@nomeata nomeata marked this pull request as ready for review November 14, 2024 11:32
@github-actions github-actions bot temporarily deployed to lean-lang.org/lean4/doc November 14, 2024 11:45 Inactive
@Kha Kha merged commit 6a5b122 into master Nov 14, 2024
24 checks passed
Kha pushed a commit that referenced this pull request Nov 14, 2024
This PR prepares #6068 by using the `RArray` data structure in
`simp_arith` the simp-arith meta code.

After the subsequent stage0 we can change the simp-arith theorems in
`Init`.
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 changes-stage0 Contains stage0 changes, merge manually using rebase release-ci Enable all CI checks for a PR, like is done for releases 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.

4 participants