mhonert / velvet-chess

:chess_pawn: Velvet Chess Engine - written in Rust
GNU General Public License v3.0
42 stars 2 forks source link

bench, pgo, release profile #13

Closed mibere closed 1 week ago

mibere commented 3 months ago

Hi there,

are there plans to implement a 'bench' command, that can be used for PGO during compilation and to compare different compile settings?

And, is there a benefit to set a release profile in Cargo.toml?

[profile.release]
...

with settings like opt-level, lto, panic, strip

Here we read

If you want to maximize runtime speed, consider all of the following: codegen-units = 1, lto = "fat", an alternative allocator, and panic = "abort".

Example

[profile.release]
codegen-units = 1
opt-level = 3
lto = = "fat"
panic = "abort"
strip = true

Thanks for your engine, your time and work. Keep on!

mhonert commented 3 months ago

Hi,

thanks for the suggestions. A while ago, I compared the performance impact of several options and also had a look at PGO. Back then, my conclusion was to leave most parameters to the defaults, but only set "codegen-units = 1" in the Cargo.toml (opt-level 3 is already the default for release builds). It increased compile times significantly, but also produced the most performant code (at least on the 3 CPUs I tested).

But in the meantime, new Rust and LLVM versions have been released and it might make sense to check the best parameters again. I did a short test today with the default setting for codegen-units (which is 16 for release builds) and with lto set to "thin" and it was slightly faster.

I will do some more comparisons and also implement a bench command for the next release.

Best regards.

mibere commented 3 months ago

For the sake of completeness, just found the default settings for the release profile.

In regard to performance, what I have read most often for a release is codegen-units = 1 + panic = "abort" + enabled LTO.

I was able to successfully compile the engine with MSYS2 (Rust 1.79.0, Clang 18.1.8). Sadly, no PGO is possible with it. Seems for that you have to install Rust natively and VS C++ Build tools with Clang.

mhonert commented 1 month ago

I just released v8.0.0, which added the "bench" command.