Skip to content

Commit

Permalink
Codegen fixes for CachedRange IEnumerable overload
Browse files Browse the repository at this point in the history
- Sacrifice ordering by expiration in quicklist when inserting from IEnumerable to reduce loop body size
- Add benchmarks to track actual CachedRange perf
- Add PolySharp to work towards removing hand-rolled polyfills for older targets
  • Loading branch information
neon-sunset committed Nov 5, 2022
1 parent 799f2d3 commit 512bbb6
Show file tree
Hide file tree
Showing 7 changed files with 800 additions and 769 deletions.
4 changes: 2 additions & 2 deletions src/FastCache.Benchmarks/FastCache.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -20,7 +20,7 @@
<PackageReference Include="CacheManager.Microsoft.Extensions.Caching.Memory" Version="1.2.0" />
<PackageReference Include="LazyCache" Version="2.4.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
<PackageReference Include="System.Runtime.Caching" Version="6.0.0" />
<PackageReference Include="RangeExtensions" Version="1.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/FastCache.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run();
BenchmarkSwitcher
.FromAssembly(typeof(Program).Assembly)
.Run();
43 changes: 43 additions & 0 deletions src/FastCache.Benchmarks/RangeWritesOverloads.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using FastCache.Collections;

namespace FastCache.Benchmarks;

[ShortRunJob, MemoryDiagnoser]
// [DisassemblyDiagnoser(maxDepth: 3, exportCombinedDisassemblyReport: true)]
public class RangeWritesOverloads
{
private (int, string)[] _array = Array.Empty<(int, string)>();

private List<(int, string)> _list = new();

private (int[], string[]) _kvpArrays = (Array.Empty<int>(), Array.Empty<string>());

[Params(1000, 1_000_000)]
public int Length;

[GlobalSetup]
public void Setup()
{
var seed = (0..Length).AsEnumerable().Select(key => (key, $"{key}")).ToArray();

_array = seed;
_list = seed.ToList();
_kvpArrays = (
seed.Select(kvp => kvp.key).ToArray(),
seed.Select(kvp => kvp.Item2).ToArray());
}

[Benchmark(Baseline = true)]
public void SaveArray() => CachedRange<string>.Save(_array, TimeSpan.MaxValue);

[Benchmark]
public void SaveList() => CachedRange<string>.Save(_list, TimeSpan.MaxValue);

[Benchmark]
public void SaveSplitArr() =>
CachedRange<string>.Save(_kvpArrays.Item1, _kvpArrays.Item2, TimeSpan.MaxValue);

[Benchmark]
public void SaveEnumerable() =>
CachedRange<string>.Save(_array.Select(kvp => kvp), TimeSpan.MaxValue);
}
Loading

0 comments on commit 512bbb6

Please sign in to comment.