Repository navigation
perf(engine): optimize FEN, repetition tracking, and game import/export - #17
Merged
Merged
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduce allocations and repeated work when replaying, restoring, and exporting games.
PlyCount, indexed FEN access, and span-based formatting.ChessGame.FromRecordJsonand PGN parsing overloads that return the game built during validation, avoiding a second replay.Validation
The following checks were completed during implementation:
Coverage includes FEN buffer boundaries, arbitrary-precision counters, history and undo, repetition equality and hash collisions, legal and pinned en passant, import diagnostics, and document/game independence.
Local benchmarks and allocation probes covered 0-, 20-, and 120-ply games. Selected 120-ply results:
Parse + ToGameversus direct import, same final buildThese are separate comparisons from short local in-process measurements, not cumulative gains or server-load results. Raw reports and allocation probes are retained locally under ignored
artifacts/benchmarks/.Validation limits:
Compatibility and risks
Existing public signatures, serialization formats, and PGN output contracts are preserved. New public APIs are additive.
Historystill returns an independent snapshot and materializes its FEN strings when accessed. Callers can use indexed or span-based FEN access to avoid requesting the entire snapshot.Direct imports preserve validation, history, undo, counters, and repetition state. PGN documents remain independent of subsequent game changes, and their declared result remains separate from the engine outcome. Failed PGN
TryParsecalls expose neither a partial document nor a partial game.Review should focus on repetition identity, en passant normalization, and restoration/undo behavior. Allocation reductions depend on the workload; collection growth and arbitrary-precision arithmetic can still allocate.
The package version remains 1.1.0; this PR does not publish a release.
Checklist