Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Move TT outside of Engine: instantiated at top level (Program.cs) #1185

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Lynx.Cli/Lynx.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<!--In favour of tiered compilation-->
<PublishReadyToRun>false</PublishReadyToRun>

<ServerGarbageCollection>true</ServerGarbageCollection>
<ServerGarbageCollection>false</ServerGarbageCollection>
<GarbageCollectionAdaptationMode>0</GarbageCollectionAdaptationMode>

<!--https://learn.microsoft.com/en-us/dotnet/core/compatibility/interop/9.0/cet-support-->
Expand Down
6 changes: 5 additions & 1 deletion src/Lynx.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Lynx;
using Lynx.Cli;
using Lynx.Model;
using Lynx.UCI.Commands.Engine;
using Microsoft.Extensions.Configuration;
using NLog;
Expand Down Expand Up @@ -32,7 +33,10 @@
using CancellationTokenSource source = new();
CancellationToken cancellationToken = source.Token;

var engine = new Engine(engineChannel);
var ttLength = TranspositionTableExtensions.CalculateLength(Configuration.EngineSettings.TranspositionTableSize);
var tt = GC.AllocateArray<TranspositionTableElement>(ttLength, pinned: true);

var engine = new Engine(engineChannel, tt);
var uciHandler = new UCIHandler(uciChannel, engineChannel, engine);

var tasks = new List<Task>
Expand Down
4 changes: 2 additions & 2 deletions src/Lynx/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public sealed partial class Engine
private CancellationTokenSource _searchCancellationTokenSource;
private CancellationTokenSource _absoluteSearchCancellationTokenSource;

public Engine(ChannelWriter<object> engineWriter)
public Engine(ChannelWriter<object> engineWriter, TranspositionTable tt)
{
AverageDepth = 0;
Game = new Game(Constants.InitialPositionFEN);
Expand All @@ -73,7 +73,7 @@ public Engine(ChannelWriter<object> engineWriter)
_killerMoves[i] = new Move[3];
}

AllocateTT();
_tt = tt;

#if !DEBUG
// Temporary channel so that no output is generated
Expand Down
Loading