Improving engine evaluation

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: Improving engine evaluation

Post by lithander »

dangi12012 wrote: Tue May 24, 2022 10:45 am Hey can you do Ildasm on that?
https://docs.microsoft.com/en-us/dotnet ... sassembler
Or ILSpy:
https://github.com/icsharpcode/ILSpy
.Net Fiddle allows you to look at the IL code generated by different compilers:
https://dotnetfiddle.net/lnIiGu

Changing the operator changes exactly one IL instruction. There's not a lot of smartness going on here. Maybe in the JITer but I can't look into that.
dangi12012 wrote: Tue May 24, 2022 10:45 am Im not sure you are measuring what you think you are :mrgreen:
I'm not sure either! ;) Just wanted to see if the modulo operator could really become a bottleneck in a workload that does a moderate amount of stuff including an array access.
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: Improving engine evaluation

Post by dangi12012 »

lithander wrote: Tue May 24, 2022 11:32 am Changing the operator changes exactly one IL instruction. There's not a lot of smartness going on here. Maybe in the JITer but I can't look into that.
Argh. You are right - the IL will not be optimized. The interesting thing would be what the JITTER compiles that into.
One way to know that would be to compile C# ahead of time:
https://docs.microsoft.com/en-us/dotnet ... ady-to-run

And finding the function in there - but thats a lot of work. So probably not worth it.

Have you tried compiling your C# engine ahead of time once? The Roslyn compiler might do more agressive optimisation when it knows it has unlimited time budget. Might give a few elo.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
User avatar
lithander
Posts: 915
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: Improving engine evaluation

Post by lithander »

hgm wrote: Tue May 24, 2022 7:28 am Btw, rather than testing the effect of the hitrate, you could (for testing purposes) put a counter in each entry to count the stores in it, to see if they are evenly distributed through the table.
If you run a search on just one position almost all slots get utilized and 90% of the slots receive less than twice the average number of stores. So it's pretty evenly distributed but with 10% of slots being "problematic" and the slots with the highest number of stores are usually written 10-100x as often than the average!

Code: Select all

Min 1 Max 66749 Average 307 >2xAverage 430/4999 8%
Min 0 Max 48099 Average 305 >2xAverage 440/4999 8%
Min 52 Max 28737 Average 416 >2xAverage 398/4999 7%
Min 49 Max 17891 Average 528 >2xAverage 410/4999 8%
Min 3 Max 6242 Average 264 >2xAverage 529/4999 10%
Min 0 Max 17800 Average 206 >2xAverage 501/4999 10%
Min 1 Max 5027 Average 106 >2xAverage 531/4999 10%
Min 94 Max 38656 Average 920 >2xAverage 417/4999 8%
Min 11 Max 4092 Average 245 >2xAverage 470/4999 9%
Min 8 Max 34323 Average 216 >2xAverage 358/4999 7%
Min 0 Max 4115 Average 80 >2xAverage 502/4999 10%
Min 0 Max 16966 Average 50 >2xAverage 396/4999 7%
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess
User avatar
lithander
Posts: 915
Joined: Sun Dec 27, 2020 2:40 am
Location: Bremen, Germany
Full name: Thomas Jahn

Re: Improving engine evaluation

Post by lithander »

hgm wrote: Tue May 24, 2022 7:28 am What I am most curious of is whether LRU replacement in buckets of 2 could drive up the hit rate.
I just gave it a try. Each lookup now involves the two slots at [index] and [index^1] and if both slots are a miss the pawnstructure is recomputed and stored in the slot that has the greater age value. Age is increased each time a slot is a queried and is reset to zero on HIT or STORE.

Here's the amount of hits and misses when searching a couple of positions from the WAC set for 1 second.

Code: Select all

Searching 1000ms per position!
PawnTable get's cleared after each search.

1 Bucket 4999 Slots
2 Buckets LRU 4999 Slots
2 Buckets LRU 9931 Slots
=================================
Hits 2637727 Misses 61948 97,71%
Hits 2798841 Misses 46617 98,36%
Hits 2758941 Misses 26596 99,05%

Hits 2178332 Misses 205202 91,39%
Hits 2248124 Misses 148529 93,80%
Hits 2239196 Misses 114131 95,15%

Hits 3229614 Misses 224592 93,50%
Hits 3153655 Misses 165840 95,00%
Hits 3335039 Misses 126698 96,34%

Hits 4201837 Misses 282386 93,70%
Hits 4313636 Misses 142726 96,80%
Hits 4357722 Misses 116622 97,39%

Hits 3672746 Misses 134204 96,47%
Hits 3663862 Misses 87710 97,66%
Hits 3706643 Misses 57484 98,47%

Hits 702604 Misses 171 99,98%
Hits 689852 Misses 145 99,98%
Hits 703025 Misses 146 99,98%

Hits 3277363 Misses 769725 80,98%
Hits 3331465 Misses 665734 83,34%
Hits 3446251 Misses 543812 86,37%

Hits 4208664 Misses 133985 96,91%
Hits 4146279 Misses 73123 98,27%
Hits 4183080 Misses 51708 98,78%

Hits 4219686 Misses 134346 96,91%
Hits 4160554 Misses 116875 97,27%
Hits 4201345 Misses 83693 98,05%

Hits 3351300 Misses 126450 96,36%
Hits 3317575 Misses 68298 97,98%
Hits 3413193 Misses 49377 98,57%

Hits 2911442 Misses 193523 93,77%
Hits 2964059 Misses 119085 96,14%
Hits 3004298 Misses 83831 97,29%

Hits 2007857 Misses 16692 99,18%
Hits 1989658 Misses 9886 99,51%
Hits 2005565 Misses 7402 99,63%

Hits 3353183 Misses 315271 91,41%
Hits 3399698 Misses 255979 93,00%
Hits 3496641 Misses 182870 95,03%

Hits 4041458 Misses 232259 94,57%
Hits 4087283 Misses 147229 96,52%
Hits 4153142 Misses 105937 97,51%

Hits 2597799 Misses 153872 94,41%
Hits 2627535 Misses 100541 96,31%
Hits 2671998 Misses 70797 97,42%

Hits 3400791 Misses 694966 83,03%
Hits 3459593 Misses 616617 84,87%
Hits 3615970 Misses 485873 88,15%

Hits 3478374 Misses 790705 81,48%
Hits 3534564 Misses 672881 84,01%
Hits 3704067 Misses 558784 86,89%

Hits 103997 Misses 1 100,00%
Hits 103756 Misses 1 100,00%
Hits 104032 Misses 1 100,00%

Hits 3452929 Misses 412389 89,33%
Hits 3550849 Misses 306834 92,05%
Hits 3622341 Misses 221064 94,25%

Hits 3131489 Misses 471872 86,90%
Hits 3203468 Misses 351343 90,12%
Hits 3275467 Misses 287250 91,94%

Hits 2674026 Misses 117019 95,81%
Hits 2621866 Misses 68520 97,45%
Hits 2661838 Misses 44464 98,36%

Hits 3556201 Misses 647636 84,59%
Hits 3580963 Misses 525619 87,20%
Hits 3766556 Misses 420856 89,95%

Hits 4128535 Misses 542295 88,39%
Hits 4125601 Misses 465709 89,86%
Hits 4241775 Misses 390068 91,58%
Minimal Chess (simple, open source, C#) - Youtube & Github
Leorik (competitive, in active development, C#) - Github & Lichess