From 65b04e7d4fd1bc48ff0ac4772b2071e0826d58dd Mon Sep 17 00:00:00 2001 From: Alex Peck Date: Sun, 3 Dec 2023 22:33:52 -0800 Subject: [PATCH 1/2] agg opt --- BitFaster.Caching/Lfu/CmSketchCore.cs | 8 +++++++- BitFaster.Caching/Lfu/ConcurrentLfuCore.cs | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/BitFaster.Caching/Lfu/CmSketchCore.cs b/BitFaster.Caching/Lfu/CmSketchCore.cs index cdd70336..4c85da1e 100644 --- a/BitFaster.Caching/Lfu/CmSketchCore.cs +++ b/BitFaster.Caching/Lfu/CmSketchCore.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; - +using System.Runtime.CompilerServices; + + #if !NETSTANDARD2_0 using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; @@ -122,6 +124,7 @@ private void EnsureCapacity(long maximumSize) size = 0; } + [MethodImpl((MethodImplOptions)512)] private unsafe int EstimateFrequencyStd(T value) { var count = stackalloc int[4]; @@ -139,6 +142,7 @@ private unsafe int EstimateFrequencyStd(T value) return Math.Min(Math.Min(count[0], count[1]), Math.Min(count[2], count[3])); } + [MethodImpl((MethodImplOptions)512)] private unsafe void IncrementStd(T value) { var index = stackalloc int[8]; @@ -226,6 +230,7 @@ private void Reset() } #if !NETSTANDARD2_0 + [MethodImpl((MethodImplOptions)512)] private unsafe int EstimateFrequencyAvx(T value) { int blockHash = Spread(comparer.GetHashCode(value)); @@ -269,6 +274,7 @@ private unsafe int EstimateFrequencyAvx(T value) } } + [MethodImpl((MethodImplOptions)512)] private unsafe void IncrementAvx(T value) { int blockHash = Spread(comparer.GetHashCode(value)); diff --git a/BitFaster.Caching/Lfu/ConcurrentLfuCore.cs b/BitFaster.Caching/Lfu/ConcurrentLfuCore.cs index 387e1d93..0c09282b 100644 --- a/BitFaster.Caching/Lfu/ConcurrentLfuCore.cs +++ b/BitFaster.Caching/Lfu/ConcurrentLfuCore.cs @@ -423,6 +423,7 @@ private void ScheduleAfterWrite() } } + [MethodImpl((MethodImplOptions)512)] private void TryScheduleDrain() { if (this.drainStatus.VolatileRead() >= DrainStatus.ProcessingToIdle) @@ -481,6 +482,7 @@ internal void DrainBuffers() } } + [MethodImpl((MethodImplOptions)512)] private bool Maintenance(N droppedWrite = null) { this.drainStatus.VolatileWrite(DrainStatus.ProcessingToIdle); @@ -534,6 +536,7 @@ private bool Maintenance(N droppedWrite = null) return done; } + [MethodImpl((MethodImplOptions)512)] private void OnAccess(LfuNode node) { // there was a cache hit even if the item was removed or is not yet added. @@ -559,6 +562,7 @@ private void OnAccess(LfuNode node) } } + [MethodImpl((MethodImplOptions)512)] private void OnWrite(LfuNode node) { // Nodes can be removed while they are in the write buffer, in which case they should @@ -606,6 +610,7 @@ private void OnWrite(LfuNode node) } } + [MethodImpl((MethodImplOptions)512)] private void PromoteProbation(LfuNode node) { if (node.list == null) @@ -629,12 +634,14 @@ private void PromoteProbation(LfuNode node) } } + [MethodImpl((MethodImplOptions)512)] private void EvictEntries() { var candidate = EvictFromWindow(); EvictFromMain(candidate); } + [MethodImpl((MethodImplOptions)512)] private LfuNode EvictFromWindow() { LfuNode first = null; @@ -679,6 +686,7 @@ public void Next() } } + [MethodImpl((MethodImplOptions)512)] private void EvictFromMain(LfuNode candidateNode) { var victim = new EvictIterator(this.cmSketch, this.probationLru.First); // victims are LRU position in probation @@ -738,6 +746,7 @@ private void EvictFromMain(LfuNode candidateNode) } } + [MethodImpl((MethodImplOptions)512)] private bool AdmitCandidate(K candidateKey, K victimKey) { int victimFreq = this.cmSketch.EstimateFrequency(victimKey); From 6c2f2ebebeaad4227f6d705799a0931b5edefb24 Mon Sep 17 00:00:00 2001 From: Alex Peck Date: Sun, 3 Dec 2023 23:06:49 -0800 Subject: [PATCH 2/2] branch info --- .../BitFaster.Caching.ThroughputAnalysis.csproj | 4 ++++ BitFaster.Caching.ThroughputAnalysis/Host.cs | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/BitFaster.Caching.ThroughputAnalysis/BitFaster.Caching.ThroughputAnalysis.csproj b/BitFaster.Caching.ThroughputAnalysis/BitFaster.Caching.ThroughputAnalysis.csproj index a70b6f61..917e2be6 100644 --- a/BitFaster.Caching.ThroughputAnalysis/BitFaster.Caching.ThroughputAnalysis.csproj +++ b/BitFaster.Caching.ThroughputAnalysis/BitFaster.Caching.ThroughputAnalysis.csproj @@ -22,6 +22,10 @@ NU1701 + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/BitFaster.Caching.ThroughputAnalysis/Host.cs b/BitFaster.Caching.ThroughputAnalysis/Host.cs index d852ed67..a091b2d4 100644 --- a/BitFaster.Caching.ThroughputAnalysis/Host.cs +++ b/BitFaster.Caching.ThroughputAnalysis/Host.cs @@ -8,10 +8,9 @@ public class Host { public static void PrintInfo() { - var Reference = typeof(Host).Assembly; - var Version = Reference.GetName().Version; + string branch = $"({ThisAssembly.Git.Branch}" + (ThisAssembly.Git.IsDirty ? " dirty)" : ")"); - Console.WriteLine($"Throughput Analysis {Version}"); + Console.WriteLine($"Throughput Analysis {ThisAssembly.Git.BaseTag} {ThisAssembly.Git.Commit} {branch}"); var hostinfo = HostEnvironmentInfo.GetCurrent();