From 39af9096ef960d6ac2480d7561c9b24b910208a7 Mon Sep 17 00:00:00 2001 From: neon_arch Date: Thu, 5 Sep 2024 22:03:23 +0530 Subject: [PATCH] :zap: perf: replace `Vec` with `Box` & initialize vectors with capacity by default (#603) --- src/cache/redis_cacher.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cache/redis_cacher.rs b/src/cache/redis_cacher.rs index 1fde95b..e6683bf 100644 --- a/src/cache/redis_cacher.rs +++ b/src/cache/redis_cacher.rs @@ -16,7 +16,7 @@ const REDIS_PIPELINE_SIZE: usize = 3; /// connect to. pub struct RedisCache { /// It stores a pool of connections ready to be used. - connection_pool: Vec, + connection_pool: Box<[ConnectionManager]>, /// It stores the size of the connection pool (in other words the number of /// connections that should be stored in the pool). pool_size: u8, @@ -58,13 +58,13 @@ impl RedisCache { })); } - let mut outputs = Vec::new(); + let mut outputs = Vec::with_capacity(tasks.len()); for task in tasks { outputs.push(task.await??); } let redis_cache = RedisCache { - connection_pool: outputs, + connection_pool: outputs.into_boxed_slice(), pool_size, current_connection: Default::default(), cache_ttl,