From 3e6fc8fda73641333bcfb1988ab36580985de1cd Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 23 Jul 2025 09:22:48 +1000 Subject: [PATCH] refactor(rust): use spinlock-based buffer pool (#9951) Profiling has shown that using a spinlock-based buffer pool is marginally (~1%) faster than the mutex-based one because it resolves contention quicker. --- rust/connlib/bufferpool/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/connlib/bufferpool/lib.rs b/rust/connlib/bufferpool/lib.rs index 160c21711..f7e09c7cd 100644 --- a/rust/connlib/bufferpool/lib.rs +++ b/rust/connlib/bufferpool/lib.rs @@ -10,7 +10,7 @@ use opentelemetry::{KeyValue, metrics::UpDownCounter}; #[derive(Clone)] pub struct BufferPool { - inner: Arc>>, + inner: Arc>>, } impl BufferPool @@ -25,7 +25,7 @@ where .build(); Self { - inner: Arc::new(lockfree_object_pool::MutexObjectPool::new( + inner: Arc::new(lockfree_object_pool::SpinLockObjectPool::new( move || { BufferStorage::new( B::with_capacity(capacity), @@ -65,8 +65,8 @@ where } pub struct Buffer { - inner: lockfree_object_pool::MutexOwnedReusable>, - pool: Arc>>, + inner: lockfree_object_pool::SpinLockOwnedReusable>, + pool: Arc>>, } impl Buffer> {