Memory optimization stuff

This commit is contained in:
Asriel Camora
2023-11-11 23:58:46 -08:00
parent 23a229364e
commit c8b963d051
2 changed files with 8 additions and 16 deletions
+1 -10
View File
@@ -18,7 +18,7 @@ public record struct SimulationState
public ActionStates ActionStates; public ActionStates ActionStates;
// https://github.com/ffxiv-teamcraft/simulator/blob/0682dfa76043ff4ccb38832c184d046ceaff0733/src/model/tables.ts#L2 // https://github.com/ffxiv-teamcraft/simulator/blob/0682dfa76043ff4ccb38832c184d046ceaff0733/src/model/tables.ts#L2
private static readonly int[] HQPercentTable = { private static ReadOnlySpan<int> HQPercentTable => new[] {
1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8,
9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 17, 17, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 17, 17,
17, 18, 18, 18, 19, 19, 20, 20, 21, 22, 23, 24, 26, 28, 31, 34, 38, 42, 47, 52, 58, 64, 68, 71, 17, 18, 18, 18, 19, 19, 20, 20, 21, 22, 23, 24, 26, 28, 31, 34, 38, 42, 47, 52, 58, 64, 68, 71,
@@ -44,13 +44,4 @@ public record struct SimulationState
ActionCount = 0; ActionCount = 0;
ActionStates = new(); ActionStates = new();
} }
#if IS_DETERMINISTIC
public override readonly string ToString()
{
var b = new System.Text.StringBuilder();
PrintMembers(b);
return Convert.ToHexString(System.Security.Cryptography.SHA256.HashData(System.Text.Encoding.UTF8.GetBytes(b.ToString())));
}
#endif
} }
+7 -6
View File
@@ -7,11 +7,11 @@ namespace Craftimizer.Solver;
// Adapted from https://github.com/dtao/ConcurrentList/blob/4fcf1c76e93021a41af5abb2d61a63caeba2adad/ConcurrentList/ConcurrentList.cs // Adapted from https://github.com/dtao/ConcurrentList/blob/4fcf1c76e93021a41af5abb2d61a63caeba2adad/ConcurrentList/ConcurrentList.cs
public struct NodeScoresBuffer public struct NodeScoresBuffer
{ {
public sealed class ScoresBatch public readonly struct ScoresBatch
{ {
public Memory<float> ScoreSum; public readonly Memory<float> ScoreSum;
public Memory<float> MaxScore; public readonly Memory<float> MaxScore;
public Memory<int> Visits; public readonly Memory<int> Visits;
public ScoresBatch() public ScoresBatch()
{ {
@@ -40,9 +40,10 @@ public struct NodeScoresBuffer
var idx = Count++; var idx = Count++;
var (arrayIdx, _) = GetArrayIndex(idx); var (arrayIdx, subIdx) = GetArrayIndex(idx);
Data[arrayIdx] ??= new(); if (subIdx == 0)
Data[arrayIdx] = new();
} }
public readonly void Visit((int arrayIdx, int subIdx) at, float score) public readonly void Visit((int arrayIdx, int subIdx) at, float score)