Skip to content

std::slice::partition_point performance regression when using rustc 1.82+ #138796

Closed
@marvin-j97

Description

@marvin-j97

In https://github.com/fjall-rs/lsm-tree I am heavily using partition_point for various binary searches.

I found the std implementation to be somewhat slow.

As you can see below, the performance regression happens between rustc 1.81 and 1.82.


Comparing std between rustc versions:

git clone https://github.com/fjall-rs/lsm-tree && cd lsm-tree
cargo +1.81 bench --bench tli
cargo +1.82 bench --bench tli

Image

The std implementation performs much worse in rustc 1.82 compared to 1.81.


As a sanity check, I wrote a simple alternative and found it performed much better (comparable to how partition_point used to be):

https://github.com/fjall-rs/lsm-tree/blob/0dca39eb54690beee2481cc3e31c9fc78d9e3fca/src/binary_search.rs#L9-L35

Reproduce (using monkey patch):

git clone https://github.com/fjall-rs/lsm-tree && cd lsm-tree
cargo +1.85 bench --bench tli
git checkout perf/replace-partition-point
cargo +1.85 bench --bench tli

Image

The hand-written binary search performs much better in 1.82+.

Looking at flame graphs, you can see a whole chunk of PartialOrd that only occurs when using the std implementation in 1.85:

Image

Image

Activity

added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Mar 21, 2025
moxian

moxian commented on Mar 22, 2025

@moxian
added
E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
I-slowIssue: Problems and improvements with respect to performance of generated code.
on Mar 22, 2025
marvin-j97

marvin-j97 commented on Mar 22, 2025

@marvin-j97
Author

Using

cargo bisect-rustc --start 2024-08-01 --end 2024-08-30 --prompt -- bench --bench tli
********************************************************************************
Regression in nightly-2024-08-03
********************************************************************************

get_commits_between returning commits, len: 8
commit[0] 2024-08-01: Auto merge of #127276 - aDotInTheVoid:no-opaque, r=camelid
commit[1] 2024-08-02: Auto merge of #127624 - Oneirical:a-test-of-lime, r=jieyouxu
commit[2] 2024-08-02: Auto merge of #128147 - lolbinarycat:fmt-write-bloat-rmake, r=jieyouxu
commit[3] 2024-08-02: Auto merge of #128529 - matthiaskrgr:rollup-gzq2slo, r=matthiaskrgr
commit[4] 2024-08-02: Auto merge of #128254 - Amanieu:orig-binary-search, r=tgross35
commit[5] 2024-08-02: Auto merge of #128352 - Oneirical:daLTOnist-vision, r=jieyouxu
commit[6] 2024-08-02: Auto merge of #127926 - Oneirical:classical-orctestra, r=jieyouxu
commit[7] 2024-08-02: Auto merge of #128361 - Oneirical:testle-deforestation, r=jieyouxu
moxian

moxian commented on Mar 22, 2025

@moxian
Contributor

that would be

@rustbot labels: +S-has-bisection -E-needs-bisection +T-libs -needs-triage -regression-untriaged +regression-from-stable-to-stable

added
S-has-bisectionStatus: A bisection has been found for this issue
T-libsRelevant to the library team, which will review and decide on the PR/issue.
regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
and removed
E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
regression-untriagedUntriaged performance or correctness regression.
on Mar 22, 2025

9 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.S-has-bisectionStatus: A bisection has been found for this issueT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Amanieu@hanna-kruppe@apiraino@moxian@marvin-j97

        Issue actions

          std::slice::partition_point performance regression when using rustc 1.82+ · Issue #138796 · rust-lang/rust