Why C++ instead of C#?

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
lithander
Posts: 915
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: Why C++ instead of C#?

Post by lithander »

Tearth wrote: Sat Jan 01, 2022 8:57 pm Be very careful with [MethodImplOptions.AggressiveInlining] - back in the time when I was writing Cosette, I've learned that overusing this attribute (especially in more complex methods) surprisingly easily leads to pretty significant performance drops.
Inlining isn't a magic bullet for sure. For example when I slap the attribute on the recursive perft function itself the binary size increases by 20kb (74KB -> 94KB) and the performance suffers a little. But every method called from within the perft function appears to receive speed gains from being inlined. I used use it on about two dozen smaller methods.

If I don't use the inlining attribute at all I lose 16M NPS (60M ->44M) regardless of whether I rely Ready-to-run compilation or the JIT. So without help C# and it's runtime obviously don't inline the enough automatically. I'm really not a fan of micro optimizations but at this point least speed gains or losses are easily verified with a set of positions and perft. And thankfully my code still performs consistent between framework .Net5 and .Net6 and different modes of compilation.
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess