From 4c33b8f356b009baefc35189add915cf44e2db89 Mon Sep 17 00:00:00 2001 From: Alex Peck Date: Thu, 8 Sep 2022 19:44:33 -0700 Subject: [PATCH 1/2] nopool --- BitFaster.Caching/Lfu/ConcurrentLfu.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/BitFaster.Caching/Lfu/ConcurrentLfu.cs b/BitFaster.Caching/Lfu/ConcurrentLfu.cs index 1b3607c4..088859c4 100644 --- a/BitFaster.Caching/Lfu/ConcurrentLfu.cs +++ b/BitFaster.Caching/Lfu/ConcurrentLfu.cs @@ -56,9 +56,7 @@ public sealed class ConcurrentLfu : ICache, IAsyncCache, IBoun private readonly IScheduler scheduler; -#if NETSTANDARD2_0 private readonly LfuNode[] drainBuffer; -#endif /// /// Initializes a new instance of the ConcurrentLfu class with the specified capacity. @@ -97,9 +95,7 @@ public ConcurrentLfu(int concurrencyLevel, int capacity, IScheduler scheduler, I this.scheduler = scheduler; -#if NETSTANDARD2_0 this.drainBuffer = new LfuNode[this.readBuffer.Capacity]; -#endif } /// @@ -689,18 +685,11 @@ private void ReFitProtected() private LfuNode[] RentDrainBuffer() { -#if !NETSTANDARD2_0 - return ArrayPool>.Shared.Rent(this.readBuffer.Capacity); -#else return drainBuffer; -#endif } private void ReturnDrainBuffer(LfuNode[] localDrainBuffer) { -#if !NETSTANDARD2_0 - ArrayPool>.Shared.Return(localDrainBuffer); -#endif } [DebuggerDisplay("{Format(),nq}")] From b8195f9f385be92260bc6f210e29ba0e25a44128 Mon Sep 17 00:00:00 2001 From: Alex Peck Date: Thu, 8 Sep 2022 19:50:42 -0700 Subject: [PATCH 2/2] cleanup --- BitFaster.Caching/Lfu/ConcurrentLfu.cs | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/BitFaster.Caching/Lfu/ConcurrentLfu.cs b/BitFaster.Caching/Lfu/ConcurrentLfu.cs index 088859c4..c432fa3e 100644 --- a/BitFaster.Caching/Lfu/ConcurrentLfu.cs +++ b/BitFaster.Caching/Lfu/ConcurrentLfu.cs @@ -12,10 +12,6 @@ using BitFaster.Caching.Lru; using BitFaster.Caching.Scheduler; -#if !NETSTANDARD2_0 -using System.Buffers; -#endif - #if DEBUG using System.Linq; using System.Text; @@ -431,26 +427,25 @@ private void DrainBuffers() private bool Maintenance(LfuNode droppedWrite = null) { this.drainStatus.Set(DrainStatus.ProcessingToIdle); - var localDrainBuffer = RentDrainBuffer(); // extract to a buffer before doing book keeping work, ~2x faster - int readCount = readBuffer.DrainTo(localDrainBuffer); + int readCount = readBuffer.DrainTo(this.drainBuffer); for (int i = 0; i < readCount; i++) { - this.cmSketch.Increment(localDrainBuffer[i].Key); + this.cmSketch.Increment(this.drainBuffer[i].Key); } for (int i = 0; i < readCount; i++) { - OnAccess(localDrainBuffer[i]); + OnAccess(this.drainBuffer[i]); } - int writeCount = this.writeBuffer.DrainTo(new ArraySegment>(localDrainBuffer)); + int writeCount = this.writeBuffer.DrainTo(new ArraySegment>(this.drainBuffer)); for (int i = 0; i < writeCount; i++) { - OnWrite(localDrainBuffer[i]); + OnWrite(this.drainBuffer[i]); } // we are done only when both buffers are empty @@ -462,8 +457,6 @@ private bool Maintenance(LfuNode droppedWrite = null) done = true; } - ReturnDrainBuffer(localDrainBuffer); - EvictEntries(); this.capacity.OptimizePartitioning(this.metrics, this.cmSketch.ResetSampleSize); ReFitProtected(); @@ -683,15 +676,6 @@ private void ReFitProtected() } } - private LfuNode[] RentDrainBuffer() - { - return drainBuffer; - } - - private void ReturnDrainBuffer(LfuNode[] localDrainBuffer) - { - } - [DebuggerDisplay("{Format(),nq}")] private class DrainStatus {