Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance by optimizing bundle merging logic. #204

Merged
merged 2 commits into from
Dec 2, 2024

Conversation

plusvic
Copy link
Contributor

@plusvic plusvic commented Dec 2, 2024

While merging two bundles, the merge_bundles function appends two sorted vectors and sort the resulting vector again. This approach used to be fast in most cases, but rustc 1.81 introduced changes in sorting algorithm that made sort_unstable_by_key to behave very bad with vectors that are almost sorted.

This introduces an optimization consisting in handling the special case where the vector being appended contains a single item differently. This case is very common, and there's a benefit in handling it differently both with rust 1.81 and with earlier versions.

Fixes #203

While merging two bundles, the `merge_bundles` function appends two sorted vectors and sort the resulting vector again. This approach used to be fast in most cases, but rustc 1.81 introduced changes in sorting algorithm that made `sort_unstable_by_key` to behave very bad with vectors are that are almost sorted.

This introduces an optimization consisting in handling the special case where the vector being appended contains a single item differently. This case is very common, and there's a benefit in handling it differently both with rust 1.81 and with earlier versions.
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for this! I'll fuzz locally for a bit just for extra caution, then cut a new release and get this into Cranelift/Wasmtime.

@cfallin
Copy link
Member

cfallin commented Dec 2, 2024

(I'm looking into the cargo-deny failure -- seems to be a license issue with a crate dependency)

@cfallin cfallin merged commit 75ccb01 into bytecodealliance:main Dec 2, 2024
6 checks passed
cfallin added a commit to cfallin/regalloc2 that referenced this pull request Dec 2, 2024
Includes bytecodealliance#204 to fix a performance regression with Rust 1.81's new
standard library sort function.
@cfallin cfallin mentioned this pull request Dec 2, 2024
cfallin added a commit that referenced this pull request Dec 2, 2024
Includes #204 to fix a performance regression with Rust 1.81's new
standard library sort function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance regression with rustc 1.81
2 participants