Skip to content

perf: single-probe cache insert in replace_rec_fn#13377

Draft
Kha wants to merge 1 commit intoleanprover:masterfrom
Kha:push-rzmrrnsrxwkq
Draft

perf: single-probe cache insert in replace_rec_fn#13377
Kha wants to merge 1 commit intoleanprover:masterfrom
Kha:push-rzmrrnsrxwkq

Conversation

@Kha
Copy link
Copy Markdown
Member

@Kha Kha commented Apr 12, 2026

This PR replaces the find-then-insert pair in replace_rec_fn::apply with a single try_emplace on descent that reserves a slot for the result, then assigns into the slot on the way up via a reference that remains stable across std::unordered_map rehashing. This halves the hash work on the shared-but-uncached path and shaves ~4% off the wall-clock of leanchecker --fresh Init.Data.List.Lemmas.

This PR replaces the find-then-insert pair in `replace_rec_fn::apply` with
a single `try_emplace` on descent that reserves a slot for the result, then
assigns into the slot on the way up via a reference that remains stable
across `std::unordered_map` rehashing. This halves the hash work on the
shared-but-uncached path and shaves ~4% off the wall-clock of
`leanchecker --fresh Init.Data.List.Lemmas`.
@Kha
Copy link
Copy Markdown
Member Author

Kha commented Apr 12, 2026

!bench

@leanprover-radar
Copy link
Copy Markdown

leanprover-radar commented Apr 12, 2026

Benchmark results for 0adccb2 against 82bb27f are in. Significant changes detected! @Kha

  • 🟥 build//instructions: +27.0G (+0.22%)

Medium changes (5🟥)

  • 🟥 elab/big_omega//instructions: +268.4M (+1.14%)
  • 🟥 elab/big_omega_MT//instructions: +263.1M (+1.11%)
  • 🟥 elab/big_struct_dep//instructions: +262.4M (+1.80%)
  • 🟥 elab/grind_ring_5//instructions: +106.8M (+1.21%)
  • 🟥 misc/leanchecker --fresh Init//instructions: +3.9G (+1.04%)

Small changes (10✅, 112🟥)

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

@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 12, 2026
@mathlib-lean-pr-testing
Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-04-09 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-12 17:05:00)

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Reference manual CI status:

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

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

Labels

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