Skip to content

Perf/solver optimizations#28

Merged
boraaros merged 2 commits into
mainfrom
perf/solver-optimizations
Mar 24, 2026
Merged

Perf/solver optimizations#28
boraaros merged 2 commits into
mainfrom
perf/solver-optimizations

Conversation

@boraaros

Copy link
Copy Markdown
Owner

No description provided.

The optimalValue in BestNodeSearch was initialized to 0 instead of the
guess parameter from the previous iteration. In MTD(f) iterative deepening
the guess carries forward the best value found at shallower depths, so
discarding it reset the search bounds unnecessarily.
Data structure changes:
- Transposition<TStep>: class -> struct (eliminates heap allocations)
- CacheTables: Dictionary -> array-based cache with power-of-2 bitmask
  indexing and KeyMarker XOR for empty slot disambiguation
  (TT: 2M slots, Eval: 8M slots)

Search algorithm improvements:
- Buffer-based move ordering: per-depth reusable List<TStep>[] replaces
  yield-return iterator state machines and per-node List allocations
- TT step legality verification: transposition table optimal step is only
  used if confirmed present in LegalStepsAt output (prevents crashes from
  Zobrist hash collisions when Position.Identifier excludes LastStep)
- IsGoal fast-path at depth 0: replaces expensive LegalStepsAt().Any()
  with O(1) IsGoal() check, reducing LegalStepsCalls by ~89%%
- HeuristicValue simplified: terminal branch removed (handled by caller)

Infrastructure:
- History heuristic recording with depth-squared weighting
  (IHeuristicTables.GetHistoryScore, not yet used for move sorting)

Benchmark results vs main (SixMaking depth-6):
  Test #1:  626ms -> 600ms  (-4%%)
  Test #3: 1457ms -> 1266ms (-13%%)
  Test #4: CRASH -> 1030ms  (fixed)
  Test #5: 16562ms -> 11218ms (-32%%)
@boraaros boraaros merged commit 4a81600 into main Mar 24, 2026
1 check passed
@boraaros boraaros deleted the perf/solver-optimizations branch March 24, 2026 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant