block_util: Avoid reallocation of Vec on push

When using DHAT[1] for analysis the amount heap allocations change from:

dhat: Total:     3,186,536 bytes in 41,452 blocks

 to

dhat: Total:     1,059,816 bytes in 34,747 blocks

When running against virtio-block; this still more allocations than
virtio-pmem but a significant improvement without any cost.

[1] https://docs.rs/dhat/latest/dhat/

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2023-01-09 17:39:43 +00:00
committed by Bo Chen
parent 9e8296b696
commit eb87538100
2 changed files with 3 additions and 3 deletions

View File

@@ -156,9 +156,8 @@ impl AsyncIo for RawFileAsync {
}
fn complete(&mut self) -> Vec<(u64, i32)> {
let mut completion_list = Vec::new();
let cq = self.io_uring.completion();
let mut completion_list = Vec::with_capacity(cq.len());
for cq_entry in cq {
completion_list.push((cq_entry.user_data(), cq_entry.result()));
}