Merge Hardcore-Performance (claude/perf-hardcore-bb2b45, b220f2b) in den Live-Stand (Owner 15.11.)

Bit-identisch (Fingerabdruecke je Entscheidung): Engine-LBR 52x, Leiter 3,3x, River-Solver-LBR 27x,
Turn-CFR 1,24x, Flop-CFR 1,41x. target-cpu=native in .cargo/config.toml, lto/cgu=1 nur im Profil mess.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 00:16:20 +01:00
co-authored by Claude Opus 5.5
253 changed files with 8372 additions and 71 deletions
+6
View File
@@ -0,0 +1,6 @@
# Built for this machine only: every binary of this tree (live rechner and benches) runs on this
# computer, so the compiler may use its instructions (POPCNT, LZCNT, BMI2, AVX2). Measured 8 % faster,
# decisions bit-identical (messung_perf/BERICHT.md). A binary built here will NOT run on a CPU
# without these instructions: for another machine remove this file (or set RUSTFLAGS="").
[build]
rustflags = ["-C", "target-cpu=native"]
+9
View File
@@ -8,3 +8,12 @@ description = "Pure, functional poker decision core. JSON lines in, JSON lines o
[profile.test]
opt-level = 2
# Perf track (messung_perf/BERICHT.md): for the measurement binaries (`cargo build --profile mess`,
# output in target/mess/). lto + one codegen unit measured bit-identical and 3 % faster; kept out of
# `release` so `cargo test --release` does not link every test binary with fat LTO. panic stays
# "unwind": main.rs and audit.rs rely on catch_unwind.
[profile.mess]
inherits = "release"
lto = "fat"
codegen-units = 1
+8
View File
@@ -0,0 +1,8 @@
bin/
prof*.txt
sprof*.txt
!*.report.txt
*.out
!test.out
*.dump
*.sorted
+114
View File
@@ -0,0 +1,114 @@
# Perf-Track: Messprogramme und Rechner schneller, bit-identisch
**Kurz (alles bit-identisch, gleicher Seed -> gleiche Decision, Hand fuer Hand):**
| Pfad | vorher -> nachher | Faktor |
|---|---|---|
| Engine-LBR Haende 0..20 (49 212 Entscheidungen) | 1157 s -> 22.2 s Wand | 52x |
| Leiter ab_zelle reg/maniac/wert-sizer | 54.3 -> 16.4 CPU-s (ohne native) | 3.3x |
| River-Solver-LBR Arm A (solver-ueberall) | 188.6 -> 7.05 CPU-s | 27x |
| Turn-Solver-Arm AB (zusaetzlich zu den obigen) | 286.7 -> 230.5 CPU-s | 1.24x |
| Flop-Solver-Arm ABC (zusaetzlich) | 61.9 -> 43.8 CPU-s, native -5 % mehr | 1.41x / 1.48x |
| Live Flop (Budget 1800 ms) | 115 -> 200 Iterationen p50, Rueckfaelle 17 -> 0 | |
| Live River p50 / Turn p50 | 976 -> 804 ms / 1710 -> 1583 ms | 1.21x / 1.08x |
Alle Zeiten wurden auf einer belasteten Maschine gemessen (Prioritaet Idle, 1 Thread), vorher und
nachher abwechselnd. "Bit-identisch" heisst: ein Fingerabdruck ueber das volle `Debug` jeder Decision
(FNV, Summe ueber alle Aufrufe) ist gleich, bzw. die Ausgabedateien sind byte-gleich.
Werkzeug dazu: `src/bin/perf_probe` (`perf_probe lbr <von> <bis> [seed]`, `perf_probe zelle <zeile> <deals>`;
`PERF_DUMP=<datei>` schreibt jede Antwort, `PERF_PROFIL=<datei>` schaltet den eingebauten Sampler ein,
`werkzeuge/perf_symbole.py` loest die Proben auf).
## Hebel (Engine-LBR, 6 Haende, Seed 7, 13 119 Entscheidungen, Fingerabdruck 9754b5c8b2a54d12)
| Hebel | Wand-s vorher -> nachher | Faktor | kumuliert | bit-identisch |
|---|---|---|---|---|
| Direkter 7-Karten-Bewerter (Farb-Lanes, `showdown::best_standard`) | 250 -> 95.5 | 2.6x | 2.6x | ja (alle 5/6/7-Karten-Haende erschoepfend geprueft) |
| Range-Filter-Cache (pro Spec/Board, Urteil pro Kartenpaar gemerkt) | 95.5 -> 40.9 | 2.3x | 6.1x | ja |
| `distinct` als Bitmaske, `deal_combo` Restmaske | 40.9 -> 24.5 | 1.64x | 10.2x | ja |
| `Pool` mit Positionstabelle, kein Vec pro Versuch, Board-Lanes einmal | 24.5 -> 12.2 | 1.9x | 20.5x | ja |
| Combos erst filtern, dann allozieren; Verfuegbarkeit ueber `at` | (12 H.) 28.6 -> 20.8 | 1.37x | ~28x | ja |
| `straight_draw`: Fenster einmal, Hold'em-Abkuerzung | Leiter 4.9/5.1 -> 3.7/3.8 CPU-s | ~1.33x | | ja (alle Rangmuster erschoepfend) |
Langer Referenzlauf LBR Haende 0..20, Seed 7 (49 212 Entscheidungen, Fingerabdruck 6c0a9a7645372cec):
**1157 s -> 34.7 s Wand / 27.2 s CPU = 33x**, identisch.
Endstand (alle Algorithmus-Hebel, ohne Compiler-Hebel, `pokerbench-perf-probe8`): **1157 s -> 29.2 s Wand / 27.3 s CPU = 40x**, Werte und
Fingerabdruck identisch (`p8_20.txt`).
Leiter `ab_zelle` (Zeilen reg, maniac, wert-sizer; 100/200 Deals; 1 Thread): **54.27 -> 20.84 CPU-s = 2.6x**,
Dateien byte-gleich.
Endstand (`pokerbench-perf-zelle8`): **54.27 -> 16.44 CPU-s = 3.3x**, alle drei Dateien byte-gleich mit `zelle0/`. Rest dort: River-Subgame-CFR (`cfr::solve`, 12 000 Iterationen) ~36 %.
River-Solver-LBR (Stand `solver-ueberall-44ecc1` 3b5cee5, Arm A: SOLVER_RIVER=1, TURN_SPIEL=grund),
4 Haende, Budgets fuer die Messung auf unendlich gestellt (sonst nicht reproduzierbar):
**207.7 -> 9.8 s Wand (188.6 -> 8.2 s CPU) = 21x**, identisch (63a7e9b3bd5b360b, 8299 Antworten 0 Abweichungen).
Patch: `solver-ueberall-perf.patch` (dieselben Hebel, `git apply` auf 3b5cee5).
## Specs
`cargo test --release -j 4` (2 Test-Threads, Idle): 1240 gruen, 10 rot, 19 ignoriert. Die 10 roten
(cfr_multi, generated_charts_plausibility, generated_charts_reproduce, pipeline_bluff,
preflop_multi_advice, preflop_plo4: Preflop-Charts) sind auf HEAD 5d4f939 ohne diese Aenderungen
genauso rot (sauberer Worktree, gleiche Tests) - nicht von diesem Track. Zusaetzlich
`the_direct_evaluator_equals_enumeration_everywhere` (#[ignore], alle 6- und 7-Karten-Haende) gruen.
## Compiler-Hebel (12 Haende LBR, CPU-s, Mittel aus 3, nach den Algorithmus-Hebeln)
| Hebel | CPU-s | Gewinn | bit-identisch |
|---|---|---|---|
| Basis (release wie bisher) | 17.77 | - | - |
| lto = "fat" | 17.52 | 1.4 % | ja |
| codegen-units = 1 | 17.49 | 1.6 % | ja |
| panic = "abort" | 17.67 | 0.6 % | ja |
| target-cpu=native (POPCNT/LZCNT/BMI2) | 16.34 | 8 % | ja |
| alles zusammen | 15.88 | 10.6 % (1.12x) | ja |
Eingebaut: `target-cpu=native` in `.cargo/config.toml` (alle Binaries dieses Baums laufen nur auf
diesem Rechner); `lto="fat"` + `codegen-units=1` als `[profile.mess]` fuer Messbinaries
(`cargo build --profile mess`), nicht in `release`, sonst linkt `cargo test --release` 144
Testbinaries mit fat LTO. `panic="abort"` nicht: main.rs und audit.rs brauchen `catch_unwind`.
## Solver-CFR (`cfr/turn_river_game.rs`, Stand solver-ueberall), bit-identisch
Hebel: `walk` ohne Allokation pro Knoten (Puffer-Vorrat, Inhalt nie vor dem Schreiben gelesen),
`show`/`show_eq` schreiben in Vorratspuffer (vorher fuellten ihre Rueckgabe-Vecs den Vorrat mit zu kleinen
Puffern -> `grow` 10 %), `matched` fuer 2/3/4 Aktionen fest ausgerollt (`Iterator::sum` faltet ab -0.0,
-0.0 + x == x bitgenau). Verworfen, weil gemessen ohne Gewinn: Null-Bloecke in `show_eq` ueberspringen
(exakt, aber Reach ist kaum blockweise 0), vier Zeilen auf einmal (langsamer, 70.7 statt 45.4 s:
Vektorisierung bricht). Festes Iterationsbudget (Wanduhr-Budgets auf unendlich), paarweise parallel gemessen:
| Arm | vorher -> nachher CPU-s | Faktor | bit-identisch |
|---|---|---|---|
| A River (SOLVER_RIVER, Haende 0..4) | 7.59 -> 7.05 | 1.08x | ja, 63a7e9b3bd5b360b (8299 Aufrufe) |
| AB Turn (+SOLVER_TURN, Haende 2..6) | 286.7 -> 230.5 | 1.24x | ja, 97e5284c0c7d7977, Dump 8196 Zeilen byte-gleich |
| ABC Flop (+SOLVER_FLOP, erste 80 Aufrufe) | 61.9 -> 43.8 | 1.41x | ja, 159b95175f3d8384, Dump byte-gleich |
Dieselben CFR-Hebel auf main (`src/cfr/turn_river_game.rs`, Turn-Spiel mit TURN_SPIEL=grund, LBR Haende 0..6):
Fingerabdruck 70ed8d3093c78a44 (11 945 Aufrufe) gleich, Dump byte-gleich, Turn-Loesung 864 -> 692 ms.
target-cpu=native zusaetzlich (paarweise, identisch): LBR 0..20 24.0 -> 21.4 CPU-s (-11 %), Flop-Arm 33.3 -> 31.8 (-5 %).
Gesamt gegenueber 3b5cee5 ohne jeden Hebel: Arm A 188.6 -> ~7.1 CPU-s (~27x).
Patch fuer solver-ueberall (alles, ohne Budget-Hack, Probe und Messhaken): `solver-ueberall-perf.patch`,
`git apply --check` sauber auf 59a9fed.
## Live: Entscheidungszeit und Iterationen im Budget
Leiterspiel (Zeile reg, 150 Deals, eine Engine-Abfrage pro echter Entscheidung), alle drei Solver an,
Budgets wie live (River 1500, Turn 1700, Flop 1800 ms), vorher/nachher gleichzeitig unter derselben Last
(Maschine voll belegt, Idle-Prioritaet: absolute ms sind ueberhoeht, der Vergleich gilt):
| Pfad | n vorher/nachher | p50 ms vorher -> nachher | p99 ms vorher -> nachher | Iterationen p50 (min) |
|---|---|---|---|---|
| Flop-Solver | 150 / 164 | 1816 -> 1665 | 1839 -> 1827 | 115 (60) -> 200 (130) |
| Flop, auf Heuristik zurueckgefallen (< 60 It.) | 17 / 0 | | | |
| Turn-Solver | 108 / 114 | 1710 -> 1583 | 1727 -> 1726 | (nicht im Grund) |
| River-Solver | 65 / 71 | 976 -> 804 | 1217 -> 1046 | 600 -> 600 (Deckel) |
| Heuristik (Engine-LBR, erste Abfrage je Zustand) | | Flop 1.8, Turn 1.8, River 1.4 (Mittel ueber alle Aufrufe vorher 23.5, nachher 0.59) | Flop 2.8, Turn 3.2, River 2.7 | |
Turn und Flop laufen live an die Budgetgrenze: schneller heisst dort mehr Iterationen bzw. kein Rueckfall auf
die Heuristik, nicht kuerzer. Live ist deshalb nicht bit-gleich (mit festem Iterationsbudget schon).
## Offen
- Leiter: `cfr::iterate`/`terminal_value` (River-Subgame, ~36 % der Leiter) mehrere Zeilen gleichzeitig.
- Turn/Flop: weitere 1.2-1.5x waeren nur mit anderer Rechenreihenfolge drin (nicht bit-gleich, nicht gebaut).
+1
View File
@@ -0,0 +1 @@
7.98 s cpu 7.59 s exit 0
+5
View File
@@ -0,0 +1,5 @@
0 2.5
1 2.5
2 2.5
3 2.5
fingerprint 63a7e9b3bd5b360b calls 8299
+7
View File
@@ -0,0 +1,7 @@
6.93 s, 8299 engine calls, 0.835 ms/call
zeit board=3 heuristik alle: n 7642 p50 0.61 ms p99 0.92 ms max 2.56 ms
zeit board=3 heuristik live: n 15 p50 1.91 ms p99 2.56 ms max 2.56 ms
zeit board=4 heuristik alle: n 499 p50 0.57 ms p99 1.02 ms max 2.16 ms
zeit board=4 heuristik live: n 1 p50 0.54 ms p99 0.54 ms max 0.54 ms
zeit board=4 turn-solver alle: n 158 p50 0.65 ms p99 1.17 ms max 1143.54 ms
zeit board=4 turn-solver live: n 2 p50 1143.54 ms p99 1143.54 ms max 1143.54 ms
+1
View File
@@ -0,0 +1 @@
7.45 s cpu 7.05 s exit 0
+5
View File
@@ -0,0 +1,5 @@
0 2.5
1 2.5
2 2.5
3 2.5
fingerprint 63a7e9b3bd5b360b calls 8299
+7
View File
@@ -0,0 +1,7 @@
6.42 s, 8299 engine calls, 0.773 ms/call
zeit board=3 heuristik alle: n 7642 p50 0.60 ms p99 1.02 ms max 3.12 ms
zeit board=3 heuristik live: n 15 p50 1.93 ms p99 2.51 ms max 2.51 ms
zeit board=4 heuristik alle: n 499 p50 0.49 ms p99 0.86 ms max 1.04 ms
zeit board=4 heuristik live: n 1 p50 0.55 ms p99 0.55 ms max 0.55 ms
zeit board=4 turn-solver alle: n 158 p50 0.64 ms p99 0.92 ms max 855.61 ms
zeit board=4 turn-solver live: n 2 p50 855.61 ms p99 855.61 ms max 855.61 ms
+1
View File
@@ -0,0 +1 @@
299.19 s cpu 286.67 s exit 0
+5
View File
@@ -0,0 +1,5 @@
2 2.5
3 2.5
4 2.5
5 2.5
fingerprint 97e5284c0c7d7977 calls 8196
+7
View File
@@ -0,0 +1,7 @@
298.16 s, 8196 engine calls, 36.378 ms/call
zeit board=3 heuristik alle: n 7539 p50 0.55 ms p99 0.95 ms max 2.47 ms
zeit board=3 heuristik live: n 15 p50 1.50 ms p99 2.47 ms max 2.47 ms
zeit board=4 heuristik alle: n 219 p50 0.34 ms p99 0.47 ms max 0.48 ms
zeit board=4 heuristik live: n 1 p50 0.41 ms p99 0.41 ms max 0.41 ms
zeit board=4 turn-solver alle: n 438 p50 886.11 ms p99 1429.58 ms max 2315.43 ms
zeit board=4 turn-solver live: n 2 p50 1167.30 ms p99 1167.30 ms max 1167.30 ms
+1
View File
@@ -0,0 +1 @@
242.20 s cpu 230.52 s exit 0
+5
View File
@@ -0,0 +1,5 @@
2 2.5
3 2.5
4 2.5
5 2.5
fingerprint 97e5284c0c7d7977 calls 8196
+7
View File
@@ -0,0 +1,7 @@
241.16 s, 8196 engine calls, 29.425 ms/call
zeit board=3 heuristik alle: n 7539 p50 0.55 ms p99 0.89 ms max 2.34 ms
zeit board=3 heuristik live: n 15 p50 1.38 ms p99 2.34 ms max 2.34 ms
zeit board=4 heuristik alle: n 219 p50 0.35 ms p99 0.42 ms max 0.63 ms
zeit board=4 heuristik live: n 1 p50 0.63 ms p99 0.63 ms max 0.63 ms
zeit board=4 turn-solver alle: n 438 p50 749.19 ms p99 1133.64 ms max 1780.44 ms
zeit board=4 turn-solver live: n 2 p50 829.14 ms p99 829.14 ms max 829.14 ms
+1
View File
@@ -0,0 +1 @@
3.35 s cpu 3.19 s exit 0
+3
View File
@@ -0,0 +1,3 @@
0 2.5
1 2.5
fingerprint 8e68d9085dfa844a calls 3749
+3
View File
@@ -0,0 +1,3 @@
2.35 s, 3749 engine calls, 0.628 ms/call
zeit board=3 heuristik alle: n 3749 p50 0.62 ms p99 0.91 ms max 2.48 ms
zeit board=3 heuristik live: n 7 p50 1.99 ms p99 2.48 ms max 2.48 ms
+1
View File
@@ -0,0 +1 @@
3.31 s cpu 3.14 s exit 0
+3
View File
@@ -0,0 +1,3 @@
0 2.5
1 2.5
fingerprint 8e68d9085dfa844a calls 3749
+3
View File
@@ -0,0 +1,3 @@
2.33 s, 3749 engine calls, 0.622 ms/call
zeit board=3 heuristik alle: n 3749 p50 0.62 ms p99 0.91 ms max 2.53 ms
zeit board=3 heuristik live: n 7 p50 1.70 ms p99 2.53 ms max 2.53 ms
+1
View File
@@ -0,0 +1 @@
629.79 s cpu 599.05 s exit -1
View File
View File
+1
View File
@@ -0,0 +1 @@
629.83 s cpu 598.52 s exit -1
View File
View File
+1
View File
@@ -0,0 +1 @@
61.98 s cpu 60.28 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
60.86 s, 80 engine calls, 760.711 ms/call
zeit board=3 flop-solver alle: n 80 p50 1411.32 ms p99 1542.06 ms max 1578.42 ms
zeit board=3 flop-solver live: n 1 p50 1515.52 ms p99 1515.52 ms max 1515.52 ms
+1
View File
@@ -0,0 +1 @@
62.38 s cpu 60.50 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
61.23 s, 80 engine calls, 765.381 ms/call
zeit board=3 flop-solver alle: n 80 p50 1397.02 ms p99 1592.77 ms max 1594.93 ms
zeit board=3 flop-solver live: n 1 p50 1520.98 ms p99 1520.98 ms max 1520.98 ms
+1
View File
@@ -0,0 +1 @@
58.94 s cpu 56.97 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
58.02 s, 80 engine calls, 725.236 ms/call
zeit board=3 flop-solver alle: n 80 p50 1337.76 ms p99 1501.89 ms max 1867.20 ms
zeit board=3 flop-solver live: n 1 p50 1360.12 ms p99 1360.12 ms max 1360.12 ms
+1
View File
@@ -0,0 +1 @@
45.53 s cpu 44.02 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
44.50 s, 80 engine calls, 556.240 ms/call
zeit board=3 flop-solver alle: n 80 p50 1000.33 ms p99 1158.33 ms max 1533.19 ms
zeit board=3 flop-solver live: n 1 p50 1053.87 ms p99 1053.87 ms max 1053.87 ms
+1
View File
@@ -0,0 +1 @@
46.42 s cpu 45.38 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
45.46 s, 80 engine calls, 568.202 ms/call
zeit board=3 flop-solver alle: n 80 p50 1072.67 ms p99 1180.75 ms max 1218.48 ms
zeit board=3 flop-solver live: n 1 p50 1106.11 ms p99 1106.11 ms max 1106.11 ms
+1
View File
@@ -0,0 +1 @@
72.62 s cpu 70.73 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
71.53 s, 80 engine calls, 894.155 ms/call
zeit board=3 flop-solver alle: n 80 p50 1665.73 ms p99 1853.10 ms max 1900.28 ms
zeit board=3 flop-solver live: n 1 p50 1792.24 ms p99 1792.24 ms max 1792.24 ms
+1
View File
@@ -0,0 +1 @@
49.39 s cpu 46.94 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
48.40 s, 80 engine calls, 605.003 ms/call
zeit board=3 flop-solver alle: n 80 p50 1124.28 ms p99 1474.31 ms max 1583.77 ms
zeit board=3 flop-solver live: n 1 p50 1132.59 ms p99 1132.59 ms max 1132.59 ms
+1
View File
@@ -0,0 +1 @@
45.44 s cpu 42.91 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
44.32 s, 80 engine calls, 554.017 ms/call
zeit board=3 flop-solver alle: n 80 p50 1009.12 ms p99 1493.21 ms max 1758.18 ms
zeit board=3 flop-solver live: n 1 p50 1003.08 ms p99 1003.08 ms max 1003.08 ms
+1
View File
@@ -0,0 +1 @@
34.12 s cpu 33.34 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
33.29 s, 80 engine calls, 416.162 ms/call
zeit board=3 flop-solver alle: n 80 p50 760.38 ms p99 860.41 ms max 873.55 ms
zeit board=3 flop-solver live: n 1 p50 830.35 ms p99 830.35 ms max 830.35 ms
+1
View File
@@ -0,0 +1 @@
32.95 s cpu 31.78 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
32.02 s, 80 engine calls, 400.190 ms/call
zeit board=3 flop-solver alle: n 80 p50 749.16 ms p99 810.44 ms max 811.09 ms
zeit board=3 flop-solver live: n 1 p50 774.07 ms p99 774.07 ms max 774.07 ms
+1
View File
@@ -0,0 +1 @@
64.59 s cpu 61.91 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
63.44 s, 80 engine calls, 792.991 ms/call
zeit board=3 flop-solver alle: n 80 p50 1465.36 ms p99 1633.52 ms max 1675.33 ms
zeit board=3 flop-solver live: n 1 p50 1558.73 ms p99 1558.73 ms max 1558.73 ms
+1
View File
@@ -0,0 +1 @@
45.90 s cpu 43.78 s exit 0
+1
View File
@@ -0,0 +1 @@
fingerprint 159b95175f3d8384 calls 80
+3
View File
@@ -0,0 +1,3 @@
44.76 s, 80 engine calls, 559.535 ms/call
zeit board=3 flop-solver alle: n 80 p50 1052.51 ms p99 1153.61 ms max 1182.30 ms
zeit board=3 flop-solver live: n 1 p50 1088.59 ms p99 1088.59 ms max 1088.59 ms
+2
View File
@@ -0,0 +1,2 @@
6 cards: 20358520 hands identical
7 cards: 133784560 hands identical
+113
View File
@@ -0,0 +1,113 @@
diff --git a/src/engine/range_filter.rs b/src/engine/range_filter.rs
index 5867544..09f59a1 100644
--- a/src/engine/range_filter.rs
+++ b/src/engine/range_filter.rs
@@ -1,4 +1,7 @@
use crate::card::{deck, Card};
+use std::cell::RefCell;
+use std::collections::HashMap;
+use std::rc::Rc;
use crate::exploit::range_spec::{Continuation, RangeSpec};
use crate::preflop::hand_percentile::percentile;
use crate::read::draw::Draw;
@@ -118,25 +121,85 @@ const RELAXED_HI: f64 = 0.5;
/// When no hand of the preflop band meets some floor, the band contradicts what the
/// villain did; the action wins and the band is relaxed to `[0, max(hi, 0.5)]`.
pub fn range_filter(spec: &RangeSpec, rules: Rules, variant: Variant, board: &[Card]) -> HandFilter {
- let board = board.to_vec();
- let (first, starved) = acceptances(spec, &rules, variant, &board);
- let (spec, qs) = if starved {
- let relaxed = RangeSpec { lo: 0.0, hi: spec.hi.max(RELAXED_HI), continues: spec.continues.clone() };
- let (qs, _) = acceptances(&relaxed, &rules, variant, &board);
- (relaxed, qs)
- } else {
- (spec.clone(), first)
+ // The range depends on (spec, rules, variant, board) only - not on hero's cards - so one decision
+ // and every decision after it at the same spot (LBR asks every combo at a node) share it: the
+ // acceptances are computed once per key, and each hand's verdict once per key and hand. Text of
+ // the key: `Debug` of f64 round-trips, so different values never share an entry.
+ let key = format!("{spec:?}|{rules:?}|{variant:?}|{board:?}");
+ let shared = FILTERS.with(|f| f.borrow().get(&key).cloned());
+ let shared = match shared {
+ Some(s) => s,
+ None => {
+ let s = Rc::new(Kept::new(spec, rules, variant, board));
+ FILTERS.with(|f| {
+ let mut f = f.borrow_mut();
+ if f.len() >= FILTER_CACHE {
+ f.clear();
+ }
+ f.insert(key, s.clone());
+ });
+ s
+ }
};
- Box::new(move |hand: &[Card]| {
- let p = percentile(variant, hand);
- p >= spec.lo
- && p <= spec.hi
- && spec.continues.iter().zip(&qs).enumerate().all(|(step, (c, q))| {
- match meets(&rules, c, hand, &board) {
+ Box::new(move |hand: &[Card]| shared.contains(hand))
+}
+
+/// Ranges kept per thread (a decision builds a few; LBR revisits one spot ~1000 times in a row).
+const FILTER_CACHE: usize = 256;
+
+thread_local! {
+ static FILTERS: RefCell<HashMap<String, Rc<Kept>>> = RefCell::new(HashMap::new());
+}
+
+/// One built range: the (possibly relaxed) spec, its ticket thresholds, and the verdict per ordered
+/// two-card hand once asked (0 = not yet, 1 = out, 2 = in).
+struct Kept {
+ spec: RangeSpec,
+ qs: Vec<f64>,
+ rules: Rules,
+ variant: Variant,
+ board: Vec<Card>,
+ verdict: RefCell<Vec<u8>>,
+}
+
+impl Kept {
+ fn new(spec: &RangeSpec, rules: Rules, variant: Variant, board: &[Card]) -> Kept {
+ let board = board.to_vec();
+ let (first, starved) = acceptances(spec, &rules, variant, &board);
+ let (spec, qs) = if starved {
+ let relaxed = RangeSpec { lo: 0.0, hi: spec.hi.max(RELAXED_HI), continues: spec.continues.clone() };
+ let (qs, _) = acceptances(&relaxed, &rules, variant, &board);
+ (relaxed, qs)
+ } else {
+ (spec.clone(), first)
+ };
+ Kept { spec, qs, rules, variant, board, verdict: RefCell::new(vec![0; 52 * 52]) }
+ }
+
+ fn judge(&self, hand: &[Card]) -> bool {
+ let p = percentile(self.variant, hand);
+ p >= self.spec.lo
+ && p <= self.spec.hi
+ && self.spec.continues.iter().zip(&self.qs).enumerate().all(|(step, (c, q))| {
+ match meets(&self.rules, c, hand, &self.board) {
Some(true) => true,
Some(false) => *q > 0.0 && ticket(hand, step) < *q,
None => false,
}
})
- })
+ }
+
+ fn contains(&self, hand: &[Card]) -> bool {
+ if hand.len() != 2 {
+ return self.judge(hand);
+ }
+ let i = hand[0].index() as usize * 52 + hand[1].index() as usize;
+ let known = self.verdict.borrow()[i];
+ if known != 0 {
+ return known == 2;
+ }
+ let v = self.judge(hand);
+ self.verdict.borrow_mut()[i] = if v { 2 } else { 1 };
+ v
+ }
}
+1
View File
@@ -0,0 +1 @@
9.07 s cpu 8.83 s exit 0
+7
View File
@@ -0,0 +1,7 @@
0 2.5
1 2.5
2 2.5
3 2.5
4 2.5
5 2.5
fingerprint 70ed8d3093c78a44 calls 11945
+7
View File
@@ -0,0 +1,7 @@
8.21 s, 11945 engine calls, 0.687 ms/call
zeit board=3 heuristik alle: n 11288 p50 0.54 ms p99 0.74 ms max 2.23 ms
zeit board=3 heuristik live: n 22 p50 1.35 ms p99 2.23 ms max 2.23 ms
zeit board=4 heuristik alle: n 499 p50 0.43 ms p99 0.73 ms max 0.78 ms
zeit board=4 heuristik live: n 1 p50 0.50 ms p99 0.50 ms max 0.50 ms
zeit board=4 turn-solver alle: n 158 p50 0.59 ms p99 0.75 ms max 864.41 ms
zeit board=4 turn-solver live: n 2 p50 864.41 ms p99 864.41 ms max 864.41 ms
+1
View File
@@ -0,0 +1 @@
8.89 s cpu 8.48 s exit 0
+7
View File
@@ -0,0 +1,7 @@
0 2.5
1 2.5
2 2.5
3 2.5
4 2.5
5 2.5
fingerprint 70ed8d3093c78a44 calls 11945
+7
View File
@@ -0,0 +1,7 @@
7.90 s, 11945 engine calls, 0.661 ms/call
zeit board=3 heuristik alle: n 11288 p50 0.54 ms p99 0.74 ms max 2.26 ms
zeit board=3 heuristik live: n 22 p50 1.55 ms p99 2.26 ms max 2.26 ms
zeit board=4 heuristik alle: n 499 p50 0.40 ms p99 0.74 ms max 0.80 ms
zeit board=4 heuristik live: n 1 p50 0.32 ms p99 0.32 ms max 0.32 ms
zeit board=4 turn-solver alle: n 158 p50 0.59 ms p99 0.70 ms max 692.49 ms
zeit board=4 turn-solver live: n 2 p50 692.49 ms p99 692.49 ms max 692.49 ms
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
21.73 s, 31464 engine calls, 0.691 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
21.40 s, 31464 engine calls, 0.680 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
21.63 s, 31464 engine calls, 0.687 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
19.97 s, 31464 engine calls, 0.635 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
21.66 s, 31464 engine calls, 0.688 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
19.49 s, 31464 engine calls, 0.620 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
21.06 s, 31464 engine calls, 0.669 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
22.07 s, 31464 engine calls, 0.701 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
19.14 s, 31464 engine calls, 0.608 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
20.04 s, 31464 engine calls, 0.637 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
20.84 s, 31464 engine calls, 0.662 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
19.00 s, 31464 engine calls, 0.604 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
26.46 s, 31464 engine calls, 0.841 ms/call
+13
View File
@@ -0,0 +1,13 @@
0 2.5
1 2.5
2 -2.5
3 2.5
4 2.5
5 2.5
6 -2.5
7 2.5
8 -5
9 2.5
10 2.5
11 4.15
fingerprint b3ac2b3a905a8ac8 calls 31464
+1
View File
@@ -0,0 +1 @@
19.94 s, 31464 engine calls, 0.634 ms/call

Some files were not shown because too many files have changed in this diff Show More