Optimize allocation paths in RawVec#43815
Merged
bors merged 3 commits intorust-lang:masterfrom Aug 13, 2017
Merged
Conversation
None of these require a significant amount of code and using `#[inline]` will allow constructors to get inlined, improving codegen at allocation callsites.
This was forgotten from rust-lang#42727 by accident, but these functions are rarely called and codegen can be improved in LLVM with the `#[cold]` tag.
Contributor
|
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
Member
Author
|
I'd like to nominate this for beta eventually, but I'd prefer to wait and see the impact on perf.rust-lang.org before deciding to do so. |
Member
|
"fatal runtime error: unsupported allocator request" |
c9e34c4 to
be9505a
Compare
kennytm
reviewed
Aug 12, 2017
src/liballoc/raw_vec.rs
Outdated
Member
There was a problem hiding this comment.
Cannot build tidy due to unused import.
[00:02:33] Compiling alloc v0.0.0 (file:///checkout/src/liballoc)
[00:02:36] error: unused import: `AllocErr`
[00:02:36] --> /checkout/src/liballoc/raw_vec.rs:16:33
[00:02:36] |
[00:02:36] 16 | use heap::{Alloc, Layout, Heap, AllocErr};
[00:02:36] | ^^^^^^^^
[00:02:36] |
[00:02:36] note: lint level defined here
[00:02:36] --> /checkout/src/liballoc/lib.rs:77:9
[00:02:36] |
[00:02:36] 77 | #![deny(warnings)]
[00:02:36] | ^^^^^^^^
[00:02:36] = note: #[deny(unused_imports)] implied by #[deny(warnings)]
[00:02:36]
[00:02:37] error: aborting due to previous error
[00:02:37]
[00:02:37] error: Could not compile `alloc`.The `RawVec` type has a number of invariants that it upholds throughout its execution, and as a result many of the runtime checks imposed by using `Layout` in a "raw" fashion aren't actually necessary. For example a `RawVec`'s capacity is intended to always match the layout which "fits" the allocation, so we don't need any runtime checks when retrieving the current `Layout` for a vector. Consequently, this adds a safe `current_layout` function which internally uses the `from_size_align_unchecked` function. Along the same lines we know that most construction of new layouts will not overflow. All allocations in `RawVec` are kept below `isize::MAX` and valid alignments are also kept low enough that we're guaranteed that `Layout` for a doubled vector will never overflow and will always succeed construction. Consequently a few locations can use `from_size_align_unchecked` in addition when constructing the *new* layout to allocate (or reallocate), which allows for eliding some more runtime checks. Overall this should significant improve performance for an important function, `RawVec::double`. This commit removes four runtime jumps before `__rust_realloc` is called, as well as one after it's called.
be9505a to
3a83165
Compare
Member
Author
|
Green! |
Member
|
@bors r+ |
Collaborator
|
📌 Commit 3a83165 has been approved by |
Collaborator
bors
added a commit
that referenced
this pull request
Aug 13, 2017
Optimize allocation paths in RawVec Since the `Alloc` trait was introduced (#42313) and it was integrated everywhere (#42727) there's been some slowdowns and regressions that have slipped through. The intention of this PR is to try to tackle at least some of them, but they've been very difficult to quantify up to this point so it probably doesn't solve everything. This PR primarily targets the `RawVec` type, specifically the `double` function. The codegen for this function is now much closer to what it was before #42313 landed as many runtime checks have been elided.
Collaborator
|
☀️ Test successful - status-appveyor, status-travis |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since the
Alloctrait was introduced (#42313) and it was integrated everywhere (#42727) there's been some slowdowns and regressions that have slipped through. The intention of this PR is to try to tackle at least some of them, but they've been very difficult to quantify up to this point so it probably doesn't solve everything.This PR primarily targets the
RawVectype, specifically thedoublefunction. The codegen for this function is now much closer to what it was before #42313 landed as many runtime checks have been elided.