generated from Nexus-Mods/NexusMods.App.Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from Nexus-Mods/rework-value-serialization
Rework value serialization
- Loading branch information
Showing
52 changed files
with
1,122 additions
and
453 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
benchmarks/NexusMods.MnemonicDB.Benchmarks/Benchmarks/IndexSegmentABenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using NexusMods.MnemonicDB.Abstractions; | ||
using NexusMods.MnemonicDB.Abstractions.DatomIterators; | ||
using NexusMods.MnemonicDB.Abstractions.ElementComparers; | ||
using NexusMods.MnemonicDB.Abstractions.IndexSegments; | ||
using NexusMods.MnemonicDB.Abstractions.Internals; | ||
using NexusMods.MnemonicDB.Storage; | ||
|
||
namespace NexusMods.MnemonicDB.Benchmarks.Benchmarks; | ||
|
||
public class IndexSegmentABenchmarks | ||
{ | ||
private readonly IndexSegment _index; | ||
|
||
public IndexSegmentABenchmarks() | ||
{ | ||
var registry = new AttributeRegistry([]); | ||
using var builder = new IndexSegmentBuilder(registry); | ||
|
||
for (int a = 1; a < 100; a++) | ||
{ | ||
var prefix = new KeyPrefix(EntityId.From(42), AttributeId.From((ushort)a), TxId.From(42), false, | ||
ValueTags.Null); | ||
builder.Add(new Datom(prefix, ReadOnlyMemory<byte>.Empty, registry)); | ||
} | ||
|
||
_index = builder.Build(); | ||
} | ||
|
||
[Params(1, 2, 3, 4, 5, 20, 30, 50, 99)] | ||
public int ToFind { get; set; } | ||
|
||
[Benchmark] | ||
public int FindLinear() | ||
{ | ||
var find = AttributeId.From((ushort)ToFind); | ||
for (var i = 0; i < _index.Count; i++) | ||
{ | ||
var datom = _index[i]; | ||
if (datom.A == find) | ||
return i; | ||
} | ||
return -1; | ||
} | ||
|
||
|
||
} |
95 changes: 95 additions & 0 deletions
95
benchmarks/NexusMods.MnemonicDB.Benchmarks/Benchmarks/IndexSegmentEBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using NexusMods.MnemonicDB.Abstractions; | ||
using NexusMods.MnemonicDB.Abstractions.DatomIterators; | ||
using NexusMods.MnemonicDB.Abstractions.ElementComparers; | ||
using NexusMods.MnemonicDB.Abstractions.IndexSegments; | ||
using NexusMods.MnemonicDB.Abstractions.Internals; | ||
using NexusMods.MnemonicDB.Storage; | ||
|
||
namespace NexusMods.MnemonicDB.Benchmarks.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class IndexSegmentEBenchmarks | ||
{ | ||
private readonly IndexSegment _index; | ||
|
||
public IndexSegmentEBenchmarks() | ||
{ | ||
var registry = new AttributeRegistry([]); | ||
using var builder = new IndexSegmentBuilder(registry); | ||
|
||
for (var e = 1; e < 100; e++) | ||
{ | ||
for (var a = 0; a < 20; a++) | ||
{ | ||
builder.Add(new Datom(new KeyPrefix(EntityId.From((ulong)e), AttributeId.From((ushort)a), TxId.From((ulong)(e + a)), false, | ||
ValueTags.Null), ReadOnlyMemory<byte>.Empty, registry)); | ||
} | ||
} | ||
|
||
_index = builder.Build(); | ||
} | ||
|
||
[Params(0, 1, 2, 3, 10, 71, 99)] public int ToFind { get; set; } | ||
|
||
|
||
[Benchmark] | ||
public int FindLinear() | ||
{ | ||
var find = EntityId.From((ulong)ToFind); | ||
for (var i = 0; i < _index.Count; i++) | ||
{ | ||
var datom = _index[i]; | ||
if (datom.E == find) | ||
return i; | ||
} | ||
return -1; | ||
} | ||
|
||
[Benchmark] | ||
public int FindBinarySearch() | ||
{ | ||
var find = EntityId.From((ulong)ToFind); | ||
|
||
var left = 0; | ||
var right = _index.Count - 1; | ||
var result = -1; | ||
while (left <= right) | ||
{ | ||
var mid = left + (right - left) / 2; | ||
var datom = _index[mid]; | ||
var comparison = datom.E.CompareTo(find); | ||
if (comparison == 0) | ||
{ | ||
result = mid; // Don't return, but continue searching to the left | ||
right = mid - 1; | ||
} | ||
else if (comparison < 0) | ||
{ | ||
left = mid + 1; | ||
} | ||
else | ||
{ | ||
right = mid - 1; | ||
} | ||
} | ||
return result; // Return the first occurrence found, or -1 if not found | ||
} | ||
|
||
[Benchmark] | ||
public int FindBinarySearchRework() | ||
{ | ||
var find = EntityId.From((ulong)ToFind); | ||
return _index.FindFirst(find); // Return the first occurrence found, or -1 if not found | ||
} | ||
|
||
[Benchmark] | ||
public int FindBinarySearchReworkAVX2() | ||
{ | ||
var find = EntityId.From((ulong)ToFind); | ||
return _index.FindFirstAVX2(find.Value); // Return the first occurrence found, or -1 if not found | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.