Skip to content

perf: worst case n log n complexity for Array.qsort - #14033

Draft
johanphenkel-cmd wants to merge 11 commits into
leanprover:masterfrom
johanphenkel-cmd:master
Draft

johanphenkel-cmd wants to merge 11 commits into
leanprover:masterfrom
johanphenkel-cmd:master

Conversation

@johanphenkel-cmd

Copy link
Copy Markdown

This PR optimizes Array.qsort to no longer take quadratic time in the worst case.

Fixes #8087

@TwoFX TwoFX self-assigned this Jun 12, 2026
@TwoFX

TwoFX commented Jun 12, 2026

Copy link
Copy Markdown
Member

!radar

@leanprover-radar

leanprover-radar commented Jun 12, 2026 •

Copy link
Copy Markdown

Benchmark results for dadc40e against f0ef737 are in. There are significant results. @TwoFX @johanphenkel-cmd @normalifelias

  • 🟥 build//instructions: +41.1G (+0.36%)

Large changes (3🟥)

  • 🟥 compiled/io_compute//instructions: +4.4G (+38.87%)
  • 🟥 misc/leanchecker --fresh Init//instructions: +11.5G (+3.19%)
  • 🟥 size/Init/.olean.private//bytes: +5MiB (+2.02%)

Medium changes (1✅, 2🟥)

  • 🟥 elab/big_omega//instructions: +185.3M (+0.87%)
  • 🟥 elab/big_omega_MT//instructions: +184.9M (+0.86%)
  • ✅ elab/bv_decide_large_aig//instructions: -1.0G (-2.55%)

Small changes (75✅, 15🟥)

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

mathlib-lean-pr-testing Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase f0ef7372e65860908c8020e146d18acfb8a65248 --onto 659e8bb858995b0a1ada239c5b3819c8f8f2772f. You can force Mathlib CI using the force-mathlib-ci label. (2026-06-12 14:57:04)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase f0ef7372e65860908c8020e146d18acfb8a65248 --onto 0758b1d2e33c65ccea578abb0c668aab1f811608. You can force Mathlib CI using the force-mathlib-ci label. (2026-06-25 13:24:49)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase f0ef7372e65860908c8020e146d18acfb8a65248 --onto 2aaf675cfd53143c757178c1a5954ded3e930ff5. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-11 16:12:33)

@leanprover-bot

leanprover-bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase f0ef7372e65860908c8020e146d18acfb8a65248 --onto 803553a556fd82fa1060efb0c43eda542130cb16. You can force reference manual CI using the force-manual-ci label. (2026-06-12 14:57:05)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase f0ef7372e65860908c8020e146d18acfb8a65248 --onto 2e72131c7f007ab9d2538b676106c5141b24ba22. You can force reference manual CI using the force-manual-ci label. (2026-06-25 13:24:51)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase f0ef7372e65860908c8020e146d18acfb8a65248 --onto 2aaf675cfd53143c757178c1a5954ded3e930ff5. You can force reference manual CI using the force-manual-ci label. (2026-07-11 16:12:35)

@hargoniX

hargoniX commented Jun 13, 2026 •

Copy link
Copy Markdown
Member

To catch up you need to at least @[inline] the 4 last wrapper functions, otherwise specialization won't pull the lt argument through all the way.

@hargoniX

Copy link
Copy Markdown
Member

!bench

@leanprover-radar

leanprover-radar commented Jun 14, 2026 •

Copy link
Copy Markdown

Benchmark results for 0f291d8 against f0ef737 are in. There are significant results. @hargoniX @normalifelias

  • 🟥 build//instructions: +59.9G (+0.53%)

Large changes (6🟥)

  • 🟥 compiled/io_compute//instructions: +4.4G (+38.86%)
  • 🟥 misc/leanchecker --fresh Init//instructions: +11.3G (+3.15%)
  • 🟥 size/Init/.olean.private//bytes: +5MiB (+1.99%)
  • 🟥 size/all/.olean.private//bytes: +11MiB (+0.85%)
  • 🟥 size/compile/.out//bytes: +15MiB (+0.63%)
  • 🟥 size/libleanshared.so//bytes: +1MiB (+0.97%)

Medium changes (1✅, 5🟥)

  • 🟥 elab/big_omega//instructions: +243.0M (+1.14%)
  • 🟥 elab/big_omega_MT//instructions: +236.4M (+1.10%)
  • ✅ elab/bv_decide_large_aig//instructions: -996.2M (-2.48%)
  • 🟥 size/all/.c//lines: +66.1k (+0.56%)
  • 🟥 size/all/.ir//bytes: +2MiB (+0.60%)
  • 🟥 size/install//bytes: +17MiB (+0.57%)

Small changes (1✅, 126🟥)

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

@hargoniX

Copy link
Copy Markdown
Member

That is quite the suprising outcome 🙃

@TwoFX

TwoFX commented Jun 25, 2026

Copy link
Copy Markdown
Member

!radar

@leanprover-radar

leanprover-radar commented Jun 25, 2026 •

Copy link
Copy Markdown

Benchmark results for c26d33b against f0ef737 are in. There are significant results. @TwoFX

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +54.1G (+0.48%)

Large changes (8🟥)

  • 🟥 compiled/io_compute//instructions: +4.4G (+38.78%)
  • 🟥 misc/leanchecker --fresh Init//instructions: +11.2G (+3.12%)
  • 🟥 size/Init/.olean.private//bytes: +5MiB (+1.99%)
  • 🟥 size/all/.c//lines: +73.3k (+0.63%)
  • 🟥 size/all/.ir//bytes: +2MiB (+0.60%)
  • 🟥 size/all/.olean.private//bytes: +11MiB (+0.88%)
  • 🟥 size/compile/.out//bytes: +15MiB (+0.64%)
  • 🟥 size/libleanshared.so//bytes: +1MiB (+0.94%)

Medium changes (2🟥)

  • 🟥 misc/leanchecker --fresh Init//maxrss: +6MiB (+1.24%)
  • 🟥 size/install//bytes: +17MiB (+0.58%)

Small changes (1✅, 126🟥)

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

@TwoFX

TwoFX commented Jun 25, 2026

Copy link
Copy Markdown
Member

!radar

@leanprover-radar

leanprover-radar commented Jun 25, 2026 •

Copy link
Copy Markdown

Benchmark results for f278a7c against f0ef737 are in. There are significant results. @TwoFX

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +41.7G (+0.37%)

Large changes (3🟥)

  • 🟥 compiled/io_compute//instructions: +4.4G (+38.78%)
  • 🟥 misc/leanchecker --fresh Init//instructions: +11.3G (+3.13%)
  • 🟥 size/Init/.olean.private//bytes: +5MiB (+2.02%)

Medium changes (2🟥)

  • 🟥 elab/big_omega//instructions: +215.3M (+1.01%)
  • 🟥 elab/big_omega_MT//instructions: +210.8M (+0.98%)

Small changes (74✅, 29🟥)

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

This branch has not been deployed

No deployments
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.

Array.qsort has quadratic runtime on constant arrays

6 participants