perf: Optimize non-prefix key strategies and
memory usage - Conditionally allocate prefix buffers in `LeafNode` and introduce `PrefixInternalNode` to reduce memory overhead when prefixes are disabled. - Bypass prefix calculation and logic entirely when `UsesPrefixes` is false. - Add a binary search fallback for key scanning. - Implement a dedicated `int` scanning fast-path, removing SIMD prefix usage from `IntStrategy`. - Reorganize key strategies into separate files. - Add a new benchmark project specifically for string keys.
This commit is contained in:
parent
570a736606
commit
9242c1c751
13 changed files with 1297 additions and 677 deletions
38
TestProject1/StandardStrategy.cs
Normal file
38
TestProject1/StandardStrategy.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
namespace PersistentMap.Tests;
|
||||
using PersistentMap;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
public class StandardStrategy
|
||||
{
|
||||
private static string GenerateRandomString(int length, Random rnd)
|
||||
{
|
||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
return new string(Enumerable.Repeat(chars, length).Select(s => s[rnd.Next(s.Length)]).ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Setup()
|
||||
{
|
||||
var N = 1000;
|
||||
var _stdStrategy = new StandardStrategy<string>();
|
||||
var _uniStrategy = new UnicodeStrategy();
|
||||
var rnd = new Random(42);
|
||||
var StringLength = 10;
|
||||
// Build random strings
|
||||
var _allKeys = Enumerable.Range(0, N).Select(_ => GenerateRandomString(StringLength, rnd)).Distinct().ToArray();
|
||||
|
||||
// Regenerate if Distinct() reduced array size (highly unlikely with length 8/50, but safe)
|
||||
while (_allKeys.Length < N)
|
||||
{
|
||||
_allKeys = _allKeys.Concat(new[] { GenerateRandomString(StringLength, rnd) }).Distinct().ToArray();
|
||||
}
|
||||
|
||||
var transStd = BaseOrderedMap<string, int, StandardStrategy<string>>.CreateTransient(_stdStrategy);
|
||||
var transUni = BaseOrderedMap<string, int, UnicodeStrategy>.CreateTransient(_uniStrategy);
|
||||
for (int i = 0; i < _allKeys.Length; i++)
|
||||
{
|
||||
transStd.Set(_allKeys[i], i);
|
||||
transUni.Set(_allKeys[i], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue