-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesA change motivated by improving speed, memory usage or compile times
Description
#[test]
fn test_quadratic() {
unsafe {
let mut vec = BlobVec::new(Layout::new::<u64>(), None, 0);
for i in 0..100_000_000 {
if i % 1_000_000 == 0 {
println!("{i}");
}
OwningPtr::make(i, |ptr| {
vec.push(ptr);
});
hint::black_box(&mut vec);
}
}
}
#[test]
fn test_quadratic_vec() {
let mut vec = Vec::new();
for i in 0..100_000_000 {
if i % 1_000_000 == 0 {
println!("{i}");
}
vec.push(i);
hint::black_box(&mut vec);
}
}Second test finishes in a second.
First test never finishes, and shows it gets slower with each iteration.
It is not noticable in typical application because:
reserve_exactbeforepush(which is howBlobVecis used) makes effect less visible (yet keeping insertion kind of quadratic)- on small
BlobVecreallocoften reallocates in place or reallocates to double size, makingpusheffectively constant even with unnecessary call torealloc. But on larger allocations malloc no longer doubles the size makingpushvery expensive.
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesA change motivated by improving speed, memory usage or compile times