Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ Improve Debug, Register, SetOption and Position UCI command parsing performance #411

Merged
merged 1 commit into from Sep 18, 2023

Conversation

eduherminio
Copy link
Member

@eduherminio eduherminio commented Sep 18, 2023

Minor improvements, and not that Debug, Register and SetOption are hit often, but here they are.

Score of Lynx 1536 - parser vs Lynx 1535 - main: 5889 - 5899 - 4112  [0.500] 15900
...      Lynx 1536 - parser playing White: 3678 - 2206 - 2067  [0.593] 7951
...      Lynx 1536 - parser playing Black: 2211 - 3693 - 2045  [0.407] 7949
...      White vs Black: 7371 - 4417 - 4112  [0.593] 15900
Elo difference: -0.2 +/- 4.6, LOS: 46.3 %, DrawRatio: 25.9 %
SPRT: llr 2.03 (68.8%), lbound -2.94, ubound 2.94
Position commands improvements (byte savings)

Current

BenchmarkDotNet v0.13.8, Ubuntu 22.04.3 LTS (Jammy Jellyfish)
Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 2 logical and 2 physical cores
.NET SDK 8.0.100-rc.1.23455.8
  [Host]     : .NET 8.0.0 (8.0.23.41904), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.0 (8.0.23.41904), X64 RyuJIT AVX2


| Method              | positionCommand      | Mean       | Error     | StdDev    | Ratio | RatioSD | Gen0   | Gen1   | Allocated | Alloc Ratio |
|-------------------- |--------------------- |-----------:|----------:|----------:|------:|--------:|-------:|-------:|----------:|------------:|
| ParseGame_Original  | position startpos    |   3.975 us | 0.0785 us | 0.1101 us |  1.00 |    0.00 | 1.1253 | 0.0992 |  27.62 KB |        1.00 |
| ParseGame_Improved1 | position startpos    |   3.798 us | 0.0594 us | 0.0526 us |  0.95 |    0.03 | 1.1215 | 0.0992 |   27.5 KB |        1.00 |
| ParseGame_Improved2 | position startpos    |   3.904 us | 0.0747 us | 0.0860 us |  0.98 |    0.03 | 1.1215 | 0.0992 |   27.5 KB |        1.00 |
| ParseGame_Improved3 | position startpos    |   3.869 us | 0.0772 us | 0.0889 us |  0.97 |    0.04 | 1.1215 | 0.0992 |  27.62 KB |        1.00 |
| ParseGame_Improved4 | position startpos    |   3.749 us | 0.0421 us | 0.0373 us |  0.93 |    0.03 | 1.1215 | 0.0992 |   27.5 KB |        1.00 |
| ParseGame_Improved5 | position startpos    |   3.597 us | 0.0513 us | 0.0480 us |  0.89 |    0.03 | 1.1215 | 0.0992 |   27.5 KB |        1.00 |
|                     |                      |            |           |           |       |         |        |        |           |             |
| ParseGame_Original  | posi(...)b7b6 [193]  |  25.784 us | 0.2080 us | 0.1844 us |  1.00 |    0.00 | 1.5564 | 0.1526 |  38.37 KB |        1.00 |
| ParseGame_Improved1 | posi(...)b7b6 [193]  |  25.000 us | 0.2459 us | 0.2300 us |  0.97 |    0.01 | 1.4954 | 0.1526 |  36.89 KB |        0.96 |
| ParseGame_Improved2 | posi(...)b7b6 [193]  |  24.916 us | 0.4187 us | 0.3917 us |  0.97 |    0.02 | 1.4038 | 0.1221 |  34.88 KB |        0.91 |
| ParseGame_Improved3 | posi(...)b7b6 [193]  |  25.537 us | 0.1953 us | 0.1827 us |  0.99 |    0.01 | 1.4648 | 0.1221 |  36.36 KB |        0.95 |
| ParseGame_Improved4 | posi(...)b7b6 [193]  |  24.221 us | 0.1648 us | 0.1542 us |  0.94 |    0.01 | 1.4038 | 0.1221 |  34.68 KB |        0.90 |
| ParseGame_Improved5 | posi(...)b7b6 [193]  |  23.195 us | 0.1498 us | 0.1328 us |  0.90 |    0.01 | 1.4038 | 0.1221 |  34.68 KB |        0.90 |
|                     |                      |            |           |           |       |         |        |        |           |             |
| ParseGame_Original  | posi(...)f3g3 [353]  |  45.627 us | 0.2196 us | 0.1946 us |  1.00 |    0.00 | 1.9531 | 0.1831 |  48.19 KB |        1.00 |
| ParseGame_Improved1 | posi(...)f3g3 [353]  |  39.608 us | 0.2803 us | 0.2622 us |  0.87 |    0.01 | 1.8311 | 0.1221 |  45.45 KB |        0.94 |
| ParseGame_Improved2 | posi(...)f3g3 [353]  |  39.863 us | 0.2684 us | 0.2511 us |  0.87 |    0.01 | 1.6479 | 0.1221 |  41.63 KB |        0.86 |
| ParseGame_Improved3 | posi(...)f3g3 [353]  |  41.310 us | 0.1837 us | 0.1534 us |  0.91 |    0.00 | 1.7700 | 0.1221 |  44.36 KB |        0.92 |
| ParseGame_Improved4 | posi(...)f3g3 [353]  |  40.074 us | 0.[3405](https://github.com/lynx-chess/Lynx/actions/runs/6221757381/job/16884332114#step:7:3406) us | 0.3185 us |  0.88 |    0.01 | 1.6479 | 0.1221 |  41.43 KB |        0.86 |
| ParseGame_Improved5 | posi(...)f3g3 [353]  |  39.640 us | 0.2858 us | 0.2674 us |  0.87 |    0.01 | 1.6479 | 0.1221 |  41.43 KB |        0.86 |
|                     |                      |            |           |           |       |         |        |        |           |             |
| ParseGame_Original  | posi(...)h3f1 [2984] | 279.670 us | 0.6095 us | 0.5701 us |  1.00 |    0.00 | 8.3008 | 0.9766 | 209.61 KB |        1.00 |
| ParseGame_Improved1 | posi(...)h3f1 [2984] | 261.998 us | 0.4168 us | 0.3899 us |  0.94 |    0.00 | 7.3242 | 0.9766 | 186.33 KB |        0.89 |
| ParseGame_Improved2 | posi(...)h3f1 [2984] | 256.380 us | 0.6834 us | 0.6058 us |  0.92 |    0.00 | 5.8594 | 0.4883 | 152.71 KB |        0.73 |
| ParseGame_Improved3 | posi(...)h3f1 [2984] | 260.596 us | 0.8465 us | 0.7504 us |  0.93 |    0.00 | 6.8359 | 0.4883 |    176 KB |        0.84 |
| ParseGame_Improved4 | posi(...)h3f1 [2984] | 243.602 us | 0.8633 us | 0.7653 us |  0.87 |    0.00 | 6.1035 | 0.4883 | 152.51 KB |        0.73 |
| ParseGame_Improved5 | posi(...)h3f1 [2984] | 241.888 us | 1.1715 us | 1.0958 us |  0.86 |    0.00 | 6.1035 | 0.4883 | 152.51 KB |        0.73 |
|                     |                      |            |           |           |       |         |        |        |           |             |
| ParseGame_Original  | posi(...)g4g8 [979]  |  99.230 us | 0.7951 us | 0.7048 us |  1.00 |    0.00 | 3.4180 | 0.3662 |  86.63 KB |        1.00 |
| ParseGame_Improved1 | posi(...)g4g8 [979]  |  91.895 us | 0.2812 us | 0.2348 us |  0.93 |    0.01 | 3.1738 | 0.2441 |  79.01 KB |        0.91 |
| ParseGame_Improved2 | posi(...)g4g8 [979]  |  89.652 us | 0.1537 us | 0.1438 us |  0.90 |    0.01 | 2.6855 | 0.2441 |  68.11 KB |        0.79 |
| ParseGame_Improved3 | posi(...)g4g8 [979]  |  94.573 us | 0.4941 us | 0.4126 us |  0.95 |    0.01 | 3.0518 | 0.2441 |  75.73 KB |        0.87 |
| ParseGame_Improved4 | posi(...)g4g8 [979]  |  88.310 us | 0.2532 us | 0.2114 us |  0.89 |    0.00 | 2.6855 | 0.2441 |  67.91 KB |        0.78 |
| ParseGame_Improved5 | posi(...)g4g8 [979]  |  89.010 us | 0.3568 us | 0.3338 us |  0.90 |    0.01 | 2.6855 | 0.2441 |  67.91 KB |        0.78 |

Previous:

 *
 BenchmarkDotNet v0.13.8, Ubuntu 22.04.3 LTS (Jammy Jellyfish)
 Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 2 logical and 2 physical cores
 .NET SDK 8.0.100-rc.1.23455.8
   [Host]     : .NET 8.0.0 (8.0.23.41904), X64 RyuJIT AVX2
   DefaultJob : .NET 8.0.0 (8.0.23.41904), X64 RyuJIT AVX2
 
 
 | Method              | positionCommand      | Mean       | Error     | StdDev    | Ratio | RatioSD | Gen0   | Gen1   | Allocated | Alloc Ratio |
 |-------------------- |--------------------- |-----------:|----------:|----------:|------:|--------:|-------:|-------:|----------:|------------:|
 | ParseGame_Original  | position startpos    |   5.437 us | 0.0792 us | 0.0741 us |  1.00 |    0.00 | 1.2131 | 0.1144 |   29.8 KB |        1.00 |
 | ParseGame_Improved1 | position startpos    |   5.339 us | 0.0611 us | 0.0542 us |  0.98 |    0.02 | 1.2054 | 0.1068 |  29.68 KB |        1.00 |
 | ParseGame_Improved2 | position startpos    |   5.265 us | 0.0925 us | 0.0865 us |  0.97 |    0.01 | 1.2054 | 0.1068 |  29.68 KB |        1.00 |
 | ParseGame_Improved3 | position startpos    |   5.423 us | 0.0604 us | 0.0535 us |  1.00 |    0.01 | 1.2131 | 0.1144 |   29.8 KB |        1.00 |
 | ParseGame_Improved4 | position startpos    |   5.745 us | 0.1125 us | 0.1104 us |  1.06 |    0.02 | 1.2131 | 0.1144 |  29.77 KB |        1.00 |
 | ParseGame_Improved5 | position startpos    |   5.429 us | 0.1045 us | 0.1499 us |  1.01 |    0.03 | 1.2131 | 0.1144 |  29.77 KB |        1.00 |
 |                     |                      |            |           |           |       |         |        |        |           |             |
 | ParseGame_Original  | posi(...)b7b6 [193]  |  26.556 us | 0.1636 us | 0.1450 us |  1.00 |    0.00 | 1.6479 | 0.1526 |  40.55 KB |        1.00 |
 | ParseGame_Improved1 | posi(...)b7b6 [193]  |  26.311 us | 0.2117 us | 0.1980 us |  0.99 |    0.01 | 1.5869 | 0.1526 |  39.07 KB |        0.96 |
 | ParseGame_Improved2 | posi(...)b7b6 [193]  |  25.852 us | 0.2180 us | 0.2039 us |  0.97 |    0.01 | 1.4954 | 0.1221 |  37.06 KB |        0.91 |
 | ParseGame_Improved3 | posi(...)b7b6 [193]  |  27.533 us | 0.2404 us | 0.2249 us |  1.04 |    0.01 | 1.5564 | 0.1526 |  38.54 KB |        0.95 |
 | ParseGame_Improved4 | posi(...)b7b6 [193]  |  26.357 us | 0.2285 us | 0.2138 us |  0.99 |    0.01 | 1.4954 | 0.1221 |  36.94 KB |        0.91 |
 | ParseGame_Improved5 | posi(...)b7b6 [193]  |  25.903 us | 0.1491 us | 0.1395 us |  0.98 |    0.01 | 1.4954 | 0.1221 |  36.94 KB |        0.91 |
 |                     |                      |            |           |           |       |         |        |        |           |             |
 | ParseGame_Original  | posi(...)f3g3 [353]  |  43.593 us | 0.2400 us | 0.2245 us |  1.00 |    0.00 | 2.0142 | 0.1831 |  50.37 KB |        1.00 |
 | ParseGame_Improved1 | posi(...)f3g3 [353]  |  42.431 us | 0.1899 us | 0.1776 us |  0.97 |    0.01 | 1.8921 | 0.1831 |  47.63 KB |        0.95 |
 | ParseGame_Improved2 | posi(...)f3g3 [353]  |  41.193 us | 0.1674 us | 0.1565 us |  0.94 |    0.01 | 1.7700 | 0.1221 |  43.81 KB |        0.87 |
 | ParseGame_Improved3 | posi(...)f3g3 [353]  |  42.969 us | 0.4555 us | 0.4038 us |  0.99 |    0.01 | 1.8921 | 0.1831 |  46.54 KB |        0.92 |
 | ParseGame_Improved4 | posi(...)f3g3 [353]  |  41.829 us | 0.2377 us | 0.2107 us |  0.96 |    0.01 | 1.7700 | 0.1221 |  43.69 KB |        0.87 |
 | ParseGame_Improved5 | posi(...)f3g3 [353]  |  41.780 us | 0.3129 us | 0.2927 us |  0.96 |    0.01 | 1.7700 | 0.1221 |  43.69 KB |        0.87 |
 |                     |                      |            |           |           |       |         |        |        |           |             |
 | ParseGame_Original  | posi(...)g4g8 [979]  |  96.149 us | 0.6131 us | 0.5735 us |  1.00 |    0.00 | 3.5400 | 0.3662 |  88.81 KB |        1.00 |
 | ParseGame_Improved1 | posi(...)g4g8 [979]  |  98.144 us | 0.4949 us | 0.4387 us |  1.02 |    0.01 | 3.2959 | 0.3662 |  81.19 KB |        0.91 |
 | ParseGame_Improved2 | posi(...)g4g8 [979]  |  97.826 us | 0.3846 us | 0.3597 us |  1.02 |    0.01 | 2.8076 | 0.2441 |  70.29 KB |        0.79 |
 | ParseGame_Improved3 | posi(...)g4g8 [979]  |  97.370 us | 0.3111 us | 0.2910 us |  1.01 |    0.01 | 3.1738 | 0.2441 |  77.91 KB |        0.88 |
 | ParseGame_Improved4 | posi(...)g4g8 [979]  |  91.612 us | 0.3654 us | 0.3418 us |  0.95 |    0.01 | 2.8076 | 0.2441 |  70.17 KB |        0.79 |
 | ParseGame_Improved5 | posi(...)g4g8 [979]  |  88.534 us | 0.3452 us | 0.3229 us |  0.92 |    0.01 | 2.8076 | 0.2441 |  70.17 KB |        0.79 |
 |                     |                      |            |           |           |       |         |        |        |           |             |
 | ParseGame_Original  | posi(...)h3f1 [2984] | 276.602 us | 0.8504 us | 0.7538 us |  1.00 |    0.00 | 8.3008 | 0.9766 | 211.79 KB |        1.00 |
 | ParseGame_Improved1 | posi(...)h3f1 [2984] | 262.196 us | 0.8526 us | 0.7975 us |  0.95 |    0.00 | 7.3242 | 0.9766 |  188.5 KB |        0.89 |
 | ParseGame_Improved2 | posi(...)h3f1 [2984] | 246.968 us | 0.9181 us | 0.8588 us |  0.89 |    0.00 | 5.8594 | 0.4883 | 154.89 KB |        0.73 |
 | ParseGame_Improved3 | posi(...)h3f1 [2984] | 260.619 us | 0.9472 us | 0.8860 us |  0.94 |    0.00 | 6.8359 | 0.4883 | 178.17 KB |        0.84 |
 | ParseGame_Improved4 | posi(...)h3f1 [2984] | 251.254 us | 2.8627 us | 2.6778 us |  0.91 |    0.01 | 5.8594 | 0.4883 | 154.77 KB |        0.73 |
 | ParseGame_Improved5 | posi(...)h3f1 [2984] | 250.528 us | 0.9854 us | 0.9217 us |  0.91 |    0.00 | 5.8594 | 0.4883 | 154.77 KB |        0.73 |

…g `Span.Split` instead of `string.Split`, which reduces allocations
@eduherminio eduherminio marked this pull request as ready for review September 18, 2023 20:54
@eduherminio eduherminio merged commit 7a1664e into main Sep 18, 2023
24 checks passed
@eduherminio eduherminio deleted the perf/command-parsing-span-split branch September 18, 2023 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant