Skip to content

chore: update to mimalloc 3.5.0 - #14866

Draft
Kha wants to merge 3 commits into
masterfrom
push-wqzmyzslmnuu
Draft

chore: update to mimalloc 3.5.0#14866
Kha wants to merge 3 commits into
masterfrom
push-wqzmyzslmnuu

Conversation

@Kha

@Kha Kha commented Aug 20, 2026

Copy link
Copy Markdown
Member

No description provided.

@Kha

Kha commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Aug 20, 2026

Copy link
Copy Markdown

Benchmark results for 03fb0d9 against 16e77c4 are in. There are significant results. @Kha

  • 🟥 build//instructions: +17.5G (+0.15%)

Large changes (14✅, 2🟥)

  • compiled/binarytrees.st//instructions: -269.8M (-0.49%)
  • compiled/binarytrees//instructions: -112.3M (-0.20%)
  • compiled/deriv//instructions: -24.9M (-0.38%)
  • compiled/ilean_roundtrip//instructions: -41.6M (-0.19%)
  • compiled/ilean_roundtrip//maxrss: -34MiB (-6.11%)
  • 🟥 compiled/io_compute//maxrss: +47MiB (+20.67%)
  • compiled/phashmap//instructions: -46.4M (-0.53%)
  • compiled/rbmap//instructions: -61.4M (-0.76%)
  • compiled/rbmap_checkpoint//instructions: -121.1M (-0.95%)
  • compiled/rbmap_checkpoint2//instructions: -71.7M (-0.84%)
  • compiled/rbmap_checkpoint2//maxrss: -2MiB (-0.57%)
  • compiled/rbmap_fbip//instructions: -97.9M (-1.42%)
  • compiled/rbmap_fbip//maxrss: -2MiB (-2.11%)
  • compiled/rbmap_library//instructions: -52.0M (-0.56%)
  • compiled/treemap//instructions: -22.1M (-0.13%)
  • 🟥 compiled/unionfind//instructions: +120.7M (+0.56%)

Medium changes (2✅, 5🟥)

  • 🟥 compiled/deriv//task-clock: +62ms (+9.58%)
  • 🟥 compiled/deriv//wall-clock: +62ms (+9.55%)
  • 🟥 compiled/incr_header_save//maxrss: +14MiB (+0.67%)
  • 🟥 compiled/nat_repr//instructions: +18.8M (+0.06%)
  • 🟥 compiled/qsort//instructions: +6.7M (+0.04%)
  • compiled/rbmap//maxrss: -2MiB (-1.92%)
  • compiled/unionfind//maxrss: -2MiB (-1.55%)

Small changes (13✅, 5🟥)

  • build/module/Lean.Elab.AutoBound//instructions: -19.7M (-1.84%)
  • build/module/Lean.Elab.Level//instructions: -19.3M (-1.23%)
  • build/module/Lean.Meta.Tactic.Grind.BitVec//instructions: -94.0M (-1.59%)
  • build/module/Lean.Meta.Tactic.Simp.BuiltinSimprocs//instructions: -16.8M (-2.27%)
  • build/module/Lean.Server.FileSource//instructions: -65.2M (-5.80%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Std.Http.Data.URI.Parser//instructions: +14.6M (+0.24%)
  • 🟥 compiled/io_compute//instructions: +3.6M (+0.03%)
  • 🟥 compiled/liasolver//instructions: +3.7M (+0.11%)
  • compiled/phashmap//maxrss: -3MiB (-3.68%)
  • elab/big_do//instructions: -30.5M (-0.17%)
  • 🟥 elab/bv_decide_large_aig//maxrss: +7MiB (+0.44%)
  • 🟥 elab/bv_decide_realworld//maxrss: +41MiB (+4.13%)
  • elab/cbv_decide//instructions: -83.0M (-0.28%)
  • elab/let_to_have_nested//instructions: -204.3M (-0.50%)
  • elab/omega_stress//instructions: -12.9M (-0.36%)
  • elab/sym_lift_lets_parallel//instructions: -36.0M (-0.60%)
  • interpreted/identifier_completion//instructions: -581.8M (-0.87%)
  • misc/leanchecker --fresh Init//instructions: -2.2G (-0.69%)

@github-actions github-actions Bot added toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN labels Aug 20, 2026
@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label Aug 20, 2026
@leanprover-bot

leanprover-bot commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ✅ Reference manual branch lean-pr-testing-14866 has successfully built against this PR. (2026-08-20 21:00:44) View Log
  • 🟡 Reference manual branch lean-pr-testing-14866 build against this PR didn't complete normally. (2026-08-20 21:01:54) View Log
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase f8facdb3303012c0d6806661867fc86e68234641 --onto 16e77c407779fde9a649adf3478204d1915371a3. You can force reference manual CI using the force-manual-ci label. (2026-08-21 09:28:49)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase f8facdb3303012c0d6806661867fc86e68234641 --onto e991a05e359a25988f49bff3ab8af986e959b866. You can force reference manual CI using the force-manual-ci label. (2026-08-31 19:35:03)

@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Aug 20, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Aug 20, 2026

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ✅ Mathlib branch lean-pr-testing-14866 has successfully built against this PR. (2026-08-20 21:49:05) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase f8facdb3303012c0d6806661867fc86e68234641 --onto 16e77c407779fde9a649adf3478204d1915371a3. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-21 09:28:48)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase f8facdb3303012c0d6806661867fc86e68234641 --onto 138ca9f20763523c4093baa092cf371e89535098. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-31 19:35:01)

@Kha
Kha force-pushed the push-wqzmyzslmnuu branch from 03fb0d9 to 606f6db Compare August 21, 2026 08:59
@Kha

Kha commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

!bench mathlib

@leanprover-radar

leanprover-radar commented Aug 31, 2026

Copy link
Copy Markdown

Benchmark results for leanprover-community/mathlib4-nightly-testing@cd03010 against leanprover-community/mathlib4-nightly-testing@5a95bed are in. There are significant results. @Kha

  • 🟥 build//instructions: +398.1G (+0.28%)

Large changes (1🟥)

  • 1 hidden

Small changes (2✅)

  • build/module/Aesop.Util.UnionFind//instructions: -26.4M (-1.53%)
  • build/module/Mathlib.Combinatorics.SimpleGraph.Coloring.VertexColoring//instructions: -55.4M (-1.76%)

Kha and others added 2 commits August 31, 2026 17:08
mimalloc 3.5.0's `e927d7b0` ("optimize page layout for malloc/free") splits `page->used++` and `--page->used` into a separate load, arithmetic and store, and hoists the load above the free-list null test. The restructuring exists to induce an `ldp` on aarch64 (the commit says so, and pairs it with an `__asm` barrier that `7c66c3f4` later widened to every GNU compiler). On x86-64 it produces no paired load and simply costs two instructions in each of `mi_malloc_small` and `mi_free`: `incw`/`incq` becomes `mov`/`inc`/`mov`.

This patch restores the single read-modify-write everywhere except aarch64, keeping the page-map flattening, the page struct reordering and the `mi_used_t = size_t` widening that the same mimalloc release brought. `mi_malloc_small` goes back to 14 instructions and `mi_free` to 18, three below 3.4.4.

Measured locally against the vendored 3.4.4 and 3.5.0, relinking only `libleanshared.so` (AMD EPYC 9455, `perf stat`, all variants rebuilt adjacently and alternated within each block):

* `compiled/unionfind` instructions -2.19% against 3.4.4 and -2.71% against 3.5.0, so the +0.54% this PR currently costs becomes a 2.2% gain
* `compiled/rbmap_fbip` -4.70% / -3.34%, `compiled/deriv` -2.21% / -1.82%
* retired macro-ops move the same way, and cycles improve 4.4-5.2% against 3.5.0 on `unionfind`

This does not address the separate `compiled/deriv` wall-clock regression, which is a locality effect of the arena and page-map redesign.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
mimalloc 3.5.0 doubled `MI_MAX_EXTEND_SIZE` from 4 KiB to 8 KiB in `932f6e5d`, a commit otherwise about guarding thread-locals against use after they are freed. Extending a page's free list in larger chunks halves the number of `_mi_malloc_generic` refills, which is why it shows up as *fewer* instructions, but it spreads each refill's writes over twice as much memory and costs `compiled/deriv` a tenth of its runtime.

Bisecting the 149 first-parent commits between the two mimalloc tags on `compiled/deriv` cycles lands on `932f6e5d` (+9.45% against 3.4.4, parent +0.70%), and reverting this one constant on top of 3.5.0 takes it from +11.58% back to +0.47%. Instruction counts cannot see any of this: the same commit *reduces* `compiled/unionfind` instructions by 25M.

With both mimalloc patches applied, against the vendored 3.4.4 (AMD EPYC 9455, min-of-6 interleaved, all variants rebuilt adjacently):

* `compiled/deriv` cycles +10.78% -> -0.24%, instructions -0.39% -> -1.65%
* `compiled/unionfind` cycles +1.82% -> -0.25%, instructions +0.53% -> -2.07%
* `compiled/rbmap_fbip` cycles -1.05% -> +0.22%, instructions -1.40% -> -3.15%

`rbmap_fbip` is the one give-back: it has 16x `unionfind`'s page churn and was the main beneficiary of the larger extend size. If radar disagrees on the trade-off across the wider suite, this commit can be dropped on its own.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Kha

Kha commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Aug 31, 2026

Copy link
Copy Markdown

Benchmark results for 80d0b29 against f8facdb are in. There are significant results. @Kha

  • build//instructions: -115.2G (-1.00%)

Large changes (19✅, 1🟥)

  • compiled/binarytrees.st//instructions: -1.5G (-2.72%)
  • compiled/binarytrees//instructions: -1.3G (-2.44%)
  • compiled/deriv//instructions: -147.0M (-2.23%)
  • compiled/hashmap//instructions: -92.5M (-2.87%)
  • compiled/ilean_roundtrip//instructions: -254.2M (-1.15%)
  • compiled/ilean_roundtrip//maxrss: -33MiB (-6.02%)
  • compiled/io_compute//instructions: -121.9M (-1.11%)
  • 🟥 compiled/io_compute//maxrss: +47MiB (+20.64%)
  • compiled/liasolver//instructions: -24.4M (-0.73%)
  • compiled/nat_repr//instructions: -424.3M (-1.25%)
  • compiled/parser//instructions: -346.7M (-0.97%)
  • compiled/phashmap//instructions: -193.5M (-2.20%)
  • compiled/qsort//instructions: -125.8M (-0.83%)
  • compiled/rbmap//instructions: -312.8M (-3.89%)
  • compiled/rbmap_checkpoint2//instructions: -323.8M (-3.77%)
  • compiled/rbmap_fbip//instructions: -334.2M (-4.84%)
  • compiled/rbmap_library//instructions: -223.2M (-2.39%)
  • compiled/treemap//instructions: -167.0M (-0.97%)
  • compiled/unionfind//instructions: -490.1M (-2.26%)
  • elab/big_do//instructions: -266.9M (-1.44%)

Medium changes (20✅)

  • build/module/Std.Data.DHashMap.Internal.RawLemmas//instructions: -3.4G (-1.37%)
  • build/module/Std.Data.DHashMap.RawLemmas//instructions: -1.5G (-1.05%)
  • build/module/Std.Data.DTreeMap.Internal.Lemmas//instructions: -2.2G (-1.01%)
  • compiled/rbmap//maxrss: -2MiB (-2.04%)
  • compiled/rbmap_checkpoint2//maxrss: -2MiB (-0.56%)
  • compiled/rbmap_fbip//maxrss: -2MiB (-1.68%)
  • compiled/select//instructions: -74.2M (-2.70%)
  • compiled/unionfind//maxrss: -2MiB (-1.59%)
  • elab/big_omega//instructions: -171.9M (-0.86%)
  • elab/big_omega_MT//instructions: -181.5M (-0.91%)
  • elab/bv_decide_mul//instructions: -336.2M (-1.03%)
  • elab/cbv_arm_ldst//instructions: -610.9M (-1.12%)
  • elab/cbv_system_f//instructions: -1.2G (-1.29%)
  • elab/grind_bitvec2//instructions: -1.7G (-1.05%)
  • elab/grind_ring_5//instructions: -89.7M (-1.06%)
  • elab/omega_stress//instructions: -51.8M (-1.42%)
  • elab/whnfMatcherImplicitTransparencyCaching//instructions: -250.6M (-1.02%)
  • interpreted/identifier_completion//instructions: -1.2G (-1.79%)
  • misc/import Std.Data.DHashMap.Internal.RawLemmas//instructions: -3.2G (-1.52%)
  • misc/leanchecker --fresh Init//instructions: -5.4G (-1.73%)

Small changes (1327✅, 3🟥)

  • build/lakeprof/longest rebuild path//instructions: -7.1G (-1.17%)
  • build/module/Init.BinderPredicates//instructions: -25.9M (-1.22%)
  • build/module/Init.CbvSimproc//instructions: -26.2M (-1.25%)
  • build/module/Init.Control.Basic//instructions: -27.3M (-1.26%)
  • build/module/Init.Control.Except//instructions: -14.6M (-1.03%)
  • build/module/Init.Control.Lawful.Basic//instructions: -22.3M (-1.04%)
  • build/module/Init.Control.Lawful.Instances//instructions: -79.5M (-1.18%)
  • build/module/Init.Control.Lawful.MonadAttach.Instances//instructions: -18.5M (-1.12%)
  • build/module/Init.Control.Lawful.MonadAttach//instructions: -5.3M (-1.05%)
  • build/module/Init.Control.Lawful.MonadLift.Instances//instructions: -12.7M (-1.09%)
  • build/module/Init.Control.Lawful.MonadLift//instructions: -5.2M (-1.04%)
  • build/module/Init.Control.Option//instructions: -10.8M (-1.24%)
  • build/module/Init.Control.State//instructions: -13.3M (-1.21%)
  • build/module/Init.Control.StateRef//instructions: -10.7M (-1.17%)
  • build/module/Init.Conv//instructions: -47.5M (-1.27%)
  • build/module/Init.Core//instructions: -114.7M (-1.15%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.Attach//instructions: -116.7M (-1.13%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.Basic//instructions: -118.7M (-1.09%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.BinSearch//instructions: -61.7M (-1.05%)
  • build/module/Init.Data.Array.Bootstrap//instructions: -24.4M (-1.05%)
  • and 1309 more
  • and 1 hidden

@Kha

Kha commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Aug 31, 2026

Copy link
Copy Markdown

Benchmark results for 66f7f14 against f8facdb are in. There are significant results. @Kha

  • build//instructions: -103.9G (-0.90%)

Large changes (18✅, 1🟥)

  • compiled/binarytrees.st//instructions: -1.3G (-2.42%)
  • compiled/binarytrees//instructions: -1.2G (-2.11%)
  • compiled/deriv//instructions: -110.2M (-1.67%)
  • compiled/hashmap//instructions: -88.9M (-2.76%)
  • compiled/ilean_roundtrip//instructions: -195.6M (-0.88%)
  • compiled/ilean_roundtrip//maxrss: -39MiB (-7.07%)
  • compiled/io_compute//instructions: -104.4M (-0.95%)
  • 🟥 compiled/io_compute//maxrss: +47MiB (+20.64%)
  • compiled/nat_repr//instructions: -345.2M (-1.02%)
  • compiled/parser//instructions: -315.1M (-0.89%)
  • compiled/phashmap//instructions: -147.7M (-1.68%)
  • compiled/qsort//instructions: -106.2M (-0.70%)
  • compiled/rbmap//instructions: -277.9M (-3.46%)
  • compiled/rbmap_checkpoint2//instructions: -279.5M (-3.26%)
  • compiled/rbmap_fbip//instructions: -220.1M (-3.19%)
  • compiled/rbmap_library//instructions: -142.3M (-1.52%)
  • compiled/treemap//instructions: -139.7M (-0.81%)
  • compiled/unionfind//instructions: -462.7M (-2.13%)
  • elab/big_do//instructions: -250.8M (-1.36%)

Medium changes (17✅)

  • build/module/Std.Data.DHashMap.Internal.RawLemmas//instructions: -3.2G (-1.31%)
  • build/module/Std.Data.DHashMap.RawLemmas//instructions: -1.5G (-1.00%)
  • build/module/Std.Data.DTreeMap.Internal.Lemmas//instructions: -2.0G (-0.93%)
  • compiled/liasolver//instructions: -22.7M (-0.68%)
  • compiled/rbmap//maxrss: -2MiB (-2.07%)
  • compiled/rbmap_checkpoint2//maxrss: -2MiB (-0.56%)
  • compiled/rbmap_fbip//maxrss: -2MiB (-1.68%)
  • compiled/select//instructions: -64.8M (-2.35%)
  • compiled/unionfind//maxrss: -2MiB (-1.59%)
  • elab/bv_decide_mul//instructions: -275.6M (-0.85%)
  • elab/cbv_arm_ldst//instructions: -562.8M (-1.03%)
  • elab/cbv_system_f//instructions: -1.1G (-1.22%)
  • elab/grind_ring_5//instructions: -72.1M (-0.85%)
  • elab/whnfMatcherImplicitTransparencyCaching//instructions: -222.2M (-0.91%)
  • interpreted/identifier_completion//instructions: -1.1G (-1.65%)
  • misc/import Std.Data.DHashMap.Internal.RawLemmas//instructions: -3.2G (-1.48%)
  • misc/leanchecker --fresh Init//instructions: -4.5G (-1.45%)

Small changes (1089✅, 1🟥)

  • build/lakeprof/longest rebuild path//instructions: -6.5G (-1.07%)
  • build/module/Init.BinderPredicates//instructions: -25.4M (-1.20%)
  • build/module/Init.CbvSimproc//instructions: -23.1M (-1.10%)
  • build/module/Init.Control.Basic//instructions: -23.8M (-1.10%)
  • build/module/Init.Control.Except//instructions: -14.1M (-0.99%)
  • build/module/Init.Control.Lawful.Basic//instructions: -21.0M (-0.98%)
  • build/module/Init.Control.Lawful.Instances//instructions: -68.3M (-1.01%)
  • build/module/Init.Control.Lawful.MonadAttach.Instances//instructions: -14.6M (-0.89%)
  • build/module/Init.Control.Lawful.MonadAttach//instructions: -4.1M (-0.81%)
  • build/module/Init.Control.Lawful.MonadLift.Instances//instructions: -10.6M (-0.91%)
  • build/module/Init.Control.Option//instructions: -9.6M (-1.10%)
  • build/module/Init.Control.State//instructions: -11.9M (-1.08%)
  • build/module/Init.Conv//instructions: -42.2M (-1.13%)
  • build/module/Init.Core//instructions: -101.6M (-1.02%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.Attach//instructions: -103.4M (-1.00%)
  • build/module/Init.Data.Array.Basic//instructions: -110.9M (-1.02%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.BinSearch//instructions: -53.6M (-0.91%)
  • build/module/Init.Data.Array.Count//instructions: -27.5M (-0.99%)
  • build/module/Init.Data.Array.Erase//instructions: -66.5M (-0.93%)
  • build/module/Init.Data.Array.Extract//instructions: -335.5M (-0.99%)
  • and 1069 more
  • and 1 hidden

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

Labels

builds-manual CI has verified that the Lean Language Reference builds against this PR builds-mathlib CI has verified that Mathlib builds against this PR 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