From cdb72797b59fcd5bbbe0cd03df35e038b4aa9158 Mon Sep 17 00:00:00 2001 From: floor-licker Date: Mon, 22 Jun 2026 20:45:05 -0400 Subject: [PATCH] fix: remove unused buffer pool --- src/buffer_pool.rs | 120 --------------------------------------------- src/client.rs | 4 -- src/lib.rs | 1 - 3 files changed, 125 deletions(-) delete mode 100644 src/buffer_pool.rs diff --git a/src/buffer_pool.rs b/src/buffer_pool.rs deleted file mode 100644 index 5e9010d..0000000 --- a/src/buffer_pool.rs +++ /dev/null @@ -1,120 +0,0 @@ -//! Buffer pooling for reducing allocation overhead -//! -//! This module provides a buffer pool for reusing memory allocations -//! across multiple HTTP requests, reducing GC pressure and improving performance. - -use std::sync::Arc; -use tokio::sync::Mutex; - -/// A pool of reusable buffers for HTTP response bodies -pub struct BufferPool { - buffers: Arc>>>, - buffer_size: usize, - max_pool_size: usize, -} - -impl BufferPool { - /// Create a new buffer pool - /// - /// # Arguments - /// * `buffer_size` - Initial size of each buffer (e.g., 512KB for typical market data) - /// * `max_pool_size` - Maximum number of buffers to keep in the pool - pub fn new(buffer_size: usize, max_pool_size: usize) -> Self { - Self { - buffers: Arc::new(Mutex::new(Vec::with_capacity(max_pool_size))), - buffer_size, - max_pool_size, - } - } - - /// Get a buffer from the pool, or create a new one if pool is empty - pub async fn get(&self) -> Vec { - let mut buffers = self.buffers.lock().await; - - match buffers.pop() { - Some(mut buffer) => { - buffer.clear(); - buffer - }, - None => { - // Pool is empty, create a new buffer - Vec::with_capacity(self.buffer_size) - }, - } - } - - /// Return a buffer to the pool - pub async fn return_buffer(&self, mut buffer: Vec) { - let mut buffers = self.buffers.lock().await; - - // Only return to pool if we're under the size limit - if buffers.len() < self.max_pool_size { - buffer.clear(); - // Shrink if buffer grew too large - if buffer.capacity() > self.buffer_size * 2 { - buffer.shrink_to(self.buffer_size); - } - buffers.push(buffer); - } - // Otherwise, let the buffer be dropped - } - - /// Get the current number of buffers in the pool - pub async fn size(&self) -> usize { - let buffers = self.buffers.lock().await; - buffers.len() - } - - /// Pre-allocate buffers in the pool - pub async fn prewarm(&self, count: usize) { - let mut buffers = self.buffers.lock().await; - for _ in 0..count.min(self.max_pool_size) { - buffers.push(Vec::with_capacity(self.buffer_size)); - } - } -} - -impl Default for BufferPool { - fn default() -> Self { - // Default: 512KB buffers, pool of 10 - Self::new(512 * 1024, 10) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[tokio::test] - async fn test_buffer_pool_get_and_return() { - let pool = BufferPool::new(1024, 5); - - let buffer = pool.get().await; - assert_eq!(buffer.capacity(), 1024); - - pool.return_buffer(buffer).await; - assert_eq!(pool.size().await, 1); - } - - #[tokio::test] - async fn test_buffer_pool_prewarm() { - let pool = BufferPool::new(1024, 5); - pool.prewarm(3).await; - assert_eq!(pool.size().await, 3); - } - - #[tokio::test] - async fn test_buffer_pool_max_size() { - let pool = BufferPool::new(1024, 2); - - let buf1 = pool.get().await; - let buf2 = pool.get().await; - let buf3 = pool.get().await; - - pool.return_buffer(buf1).await; - pool.return_buffer(buf2).await; - pool.return_buffer(buf3).await; // This should be dropped, not added to pool - - assert_eq!(pool.size().await, 2); // Max size is 2 - } -} diff --git a/src/client.rs b/src/client.rs index 9133b7c..10c1fbc 100644 --- a/src/client.rs +++ b/src/client.rs @@ -119,8 +119,6 @@ pub struct ClobClient { order_builder: Option, #[allow(dead_code)] connection_manager: Option>, - #[allow(dead_code)] - buffer_pool: std::sync::Arc, } #[derive(Default)] @@ -158,7 +156,6 @@ impl ClobClient { host.to_string(), ), )); - let buffer_pool = std::sync::Arc::new(crate::buffer_pool::BufferPool::new(512 * 1024, 10)); let order_builder = auth .signer @@ -176,7 +173,6 @@ impl ClobClient { builder_code: auth.builder_code, order_builder, connection_manager, - buffer_pool, } } diff --git a/src/lib.rs b/src/lib.rs index 1cd5921..9d7771f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -175,7 +175,6 @@ pub use crate::utils::{crypto, math, rate_limit, retry, time, url}; // Module declarations pub mod auth; pub mod book; -pub mod buffer_pool; pub mod client; pub mod connection_manager; pub mod decode;