Add inline annotations on Vec's Deref and DerefMut #52343
Closed
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.
While doing profiling on https://github.com/BurntSushi/aho-corasick I noticed that
Vec::deref_mut
would show up as a hot function despite the fact that it should be a no-op that should be trivially inlined. (as the layout ofVec<T>
is that of&[T]
+ a capacity after).I'd expect that the method(s) would usually be inlined despite the lack of an inline in most cases but for the crate in question I observed a 1.2x speedup if I replaced the deref with
::std::mem::transmute_copy
so there was definitely a noticeable performance regression.Also, I recognize that it is likely that, were I to use different version of rustc, then the problem could go away. But the fact remains that (evidently) some versions of rustc misses this optimization and maybe an inline annotation can help to avoid this.