-
-
Notifications
You must be signed in to change notification settings - Fork 755
perf(allocator): optimize Vec::push for common case that vec is not full to capacity
#9301
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
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging #9301 will not alter performanceComparing Summary
|
d7ffd68 to
3460450
Compare
|
@overlookmotel Note to self: Rebase on top of #9656 and re-run benchmarks. |
… full to capacity
3460450 to
f1145e6
Compare
Have done. Let's see... |
|
I stumbled upon a Vec::push_within_capacity method while I was looking through the standard |
Yes, I also wonder if a What I have in mind is that Outline: const VEC_BUILDER_INLINE_CAPACITY: usize = 8; // Or maybe 4 is better
pub enum VecBuilder<'a, T> {
Inline(VecBuilderInline<T>),
Allocated(Vec<'a, T>),
}
struct VecBuilderInline<T> {
data: [MaybeUninit<T>; VEC_BUILDER_INLINE_CAPACITY],
len: usize, // Cannot be more than `VEC_BUILDER_INLINE_CAPACITY`
}
impl<'a, T> VecBuilder<'a, T> {
pub fn new() -> Self {
Self::Inline(VecBuilderInline {
data: [MaybeUninit::new(); VEC_BUILDER_INLINE_CAPACITY,
len: 0,
}
}
pub fn into_vec(self) -> Vec<'a, T> {
match self {
Inline(inline_vec) => todo!("Convert to Vec"),
Allocated(vec) => vec,
}
}
}(actual implementation could be optimized to avoid branching on Usage: let mut vec_builder = VecBuilder::new();
while Some(node) = get_node_somehow() {
vec_builder.push(node);
}
let vec = vec_builder.into_vec();
I don't know how the positives and negatives would weigh against each other. Maybe when |
|
Our new |


No description provided.