perf: add three-way partitioning to Array.qsort - #14653
Conversation
|
!radar |
|
Benchmark results for 8208e78 against e51752c are in. There are significant results. @kim-em Warning These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.
Large changes (2✅)
Medium changes (3🟥)
Small changes (3✅, 86🟥)
|
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
|
!radar |
|
Benchmark results for 7a8781f against e51752c are in. There are significant results. @kim-em Warning These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.
Large changes (2✅)
Medium changes (2🟥)
Small changes (1✅, 75🟥)
|
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
This PR makes
Array.qsortefficiently handle inputs with repeated values by grouping pivot-equal elements and excluding them from recursive calls.The partitioner retains the low-overhead scan for distinct inputs and switches to a three-way partition once it encounters an element equal to the pivot. This fixes the quadratic behavior reported in #8087 without regressing the existing random-input benchmark.
qsortOrdnow passes its three-way comparison directly, while the Boolean-comparator API is adapted internally.It adds a regression test for repeated values and a Radar benchmark covering constant and low-cardinality arrays. The suggestion snapshots change because unstable sorting may now choose a different order among equal elements. The obsolete implementation-coupled proof test is removed; stacked follow-up #14658 replaces it with stronger proofs in the library.
Previous attempts and related groundwork:
grind-based verification to the test suite; #12510 later attempted to complete those proofs.Array.qsorthas quadratic runtime on constant arrays #8087, but its Radar runs showed a roughly 39% instruction regression incompiled/io_compute.io_computeperformance baseline.🤖 prepared with assistance from codex and claude