Skip to content

[aix-chess-compression] Skipping legality check on decoding for increased performance #7

Description

@franciscoBSalgueiro

Low and Medium compression could be much faster by skipping legality check when decoding.

let r = uci.to_move(&self.chess).map_err(|_| DecodeError {});
Some(r.map(|m| {
self.chess.play_unchecked(m); // uci.to_move already checks legality
self.index += 2;
m
}))

The to_move method is generating all legal moves under the hood on every single position, which is very slow. I've experimented with removing the legality check from to_move (if the movedata was created using this crate then it should always be legal) and decoding becomes >2x faster.

Changes to to_move:

// if pos.is_legal(candidate) {
Ok(candidate)
// } else {
//     Err(IllegalUciMoveError)
// }

cargo bench

decode_low              time:   [6.1855 µs 6.2020 µs 6.2204 µs]
                        change: [−54.883% −54.641% −54.385%] (p = 0.00 < 0.05)
                        Performance has improved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions