Skip to content

do not inline grow_amortized #78483

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
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions library/alloc/src/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,9 @@ impl<T, A: AllocRef> RawVec<T, A> {
// so that all of the code that depends on `T` is within it, while as much
// of the code that doesn't depend on `T` as possible is in functions that
// are non-generic over `T`.
//
// We never inline this function to keep `Vec::push` small.
#[inline(never)]
Copy link
Member

@m-ou-se m-ou-se Oct 28, 2020

Choose a reason for hiding this comment

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

In many places, #[cold] is used for this, sometimes together with #[inline(never)] on the same function. Is there some guidance somewhere on which to use where?

If these kind of functions should have #[inline(never)] instead of (or in addition to) #[cold], some of them (e.g. SyncOnceCell::initialize) should probably be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, I am not really sure. It probably depends on where it is used and we would need an additional perf run 😆

I do feel like this method is kind of special as it is extremely frequently used. Not sure if SyncOnceCell is used frequently enough for this to be noticeable. Could be worth trying though

fn grow_amortized(&mut self, len: usize, additional: usize) -> Result<(), TryReserveError> {
// This is ensured by the calling contexts.
debug_assert!(additional > 0);
Expand Down