Skip to content

Optimize the next-power-of-two calculation in vectors for code size #15390

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

Closed
pcwalton opened this issue Jul 3, 2014 · 3 comments
Closed

Optimize the next-power-of-two calculation in vectors for code size #15390

pcwalton opened this issue Jul 3, 2014 · 3 comments
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@pcwalton
Copy link
Contributor

pcwalton commented Jul 3, 2014

Currently it's more general than it needs to be, resulting in the next-power-of-two code appearing in lots of places due to inlining. But vec capacities are usually powers of two. I think it should be something like:

if popcount(capacity) != 1 {
    // non-power-of-two case
    capacity_slow()
} else {
    capacity << 1
}
@hirschenberger
Copy link
Contributor

Do you mean in the Vec::reserve method?

@thestinger
Copy link
Contributor

Ideally, the slow path would be hoisted out but it interfered with optimizations before.

@emberian
Copy link
Member

I'm going to close this. #23670 moves cap calculation out of the inlined fast path entirely.

bors added a commit to rust-lang-ci/rust that referenced this issue Aug 7, 2023
Improve mir interpreter performance by caching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

4 participants