Skip to content

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

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

perf: worst case n log n complexity for Array.qsort#14033
johanphenkel-cmd wants to merge 8 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

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)

@leanprover-bot

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)

@hargoniX

hargoniX commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

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
Contributor

!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
Contributor

That is quite the suprising outcome 🙃

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