Running a Multithreaded Rust GTO Poker Solver Locally in the Browser (WASM) and Mobile
How Viper GTO compiles one 7,900-line Rust DCFR solver to a 635 KB multithreaded WebAssembly binary and native iOS/Android libraries — including suit isomorphism, COOP/COEP traps and real benchmarks.
Key takeaway: Custom postflop GTO solving and nodelocking do not require a Windows workstation or cloud compute billing. Viper GTO runs one shared ~7,900-line Rust DCFR core as a 635 KB multithreaded WebAssembly module (468 KB single-thread fallback) in browsers and via UniFFI natively on iOS and Android, using suit isomorphism (up to 3.2× faster, 71% fewer tree nodes) to solve river trees in tens of milliseconds locally.
Ask almost any poker player or search engine how to run custom postflop GTO solves and nodelocking, and you will hear the same assumption: custom solving only works on a Windows desktop solver or an expensive cloud subscription; browsers and phones can only browse pre-solved charts.
That assumption used to be true when solvers needed gigabytes of unmanaged RAM and native x86-64 binaries. Today, modern browsers ship WebAssembly with SIMD and shared-memory threads (SharedArrayBuffer), and modern phones carry multi-core ARM CPUs faster than the laptops people ran PioSolver on five years ago.
This post documents how Viper GTO compiles one ~7,900-line Rust Discounted CFR (DCFR) solver core (viper-engine v0.1.5) across WebAssembly, iOS, and Android, the browser security traps we hit shipping multithreaded WASM in production, and the real benchmarks — plus the honest hardware boundaries that still remain.
1. One Rust DCFR core, three runtime targets
Maintaining separate poker logic across web, iOS, and Android is a recipe for silent drift — especially when hand evaluation, range parsing, rake math, and EV calculations must agree down to the decimal.
Instead, Viper GTO keeps the entire engine in a single Rust crate (viper-engine) with three compilation targets:
| Target | Binding / Runtime | Binary / Artifact | Threading |
|---|---|---|---|
| Web (multithreaded) | wasm-bindgen + wasm-bindgen-rayon (+atomics) |
635 KB (viper_engine_bg.wasm) |
Dedicated Web Worker + rayon pool (hardwareConcurrency - 1 cores) |
| Web (fallback) | wasm-bindgen (single-threaded) |
468 KB (viper_engine_bg.wasm) |
Dedicated Web Worker (1 thread, UI never blocks) |
| iOS & Android | UniFFI 0.28 (generated Swift & Kotlin bindings) | Versioned release artifact pinned by SHA-256 in engine.lock |
Native rayon thread pool on ARM64 |
Pinning mobile builds to a released artifact via engine.lock also keeps client builds fast: web, iOS, and Android builds require no Rust toolchain on CI or developer machines unless the solver itself changes.
2. Shipping multithreaded WASM without breaking production
Running rayon inside WebAssembly requires two strict response headers on app.vipergto.com:
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
Without both headers, crossOriginIsolated is false and browsers hide SharedArrayBuffer. Enabling them unlocked multi-core browser solving — and immediately surfaced two nasty real-world traps:
Trap A: initThreadPool() can hang forever instead of rejecting
In wasm-bindgen-rayon, calling initThreadPool(n) spawns nested Web Workers. In certain restricted browser environments or content-blocker configurations where nested worker spawning is blocked, the returned Promise never resolves and never rejects — leaving a solve stuck indefinitely with no error.
Our worker fixes this by racing pool initialization against an explicit 8-second timeout (THREAD_POOL_TIMEOUT_MS = 8000) and transparently falling back to the 468 KB single-threaded WASM build:
if (typeof SharedArrayBuffer !== 'undefined' && crossOriginIsolated) {
try {
const mt = await import('./mt/viper_engine.js');
await mt.default(new URL('./mt/viper_engine_bg.wasm', import.meta.url));
await withTimeout(mt.initThreadPool(n), 8000, 'initThreadPool');
return mt;
} catch {
// Fall through cleanly to single-threaded WASM
}
}
Trap B: COOP: same-origin breaks Google OAuth popups
Because Cross-Origin-Opener-Policy: same-origin isolates browsing context groups, it severs window.opener across origins. Standard Google Sign-In popup mode opens Google’s chooser, authenticates the user, and then cannot pass credentials back, leaving a blank white window.
The fix was architectural rather than a console tweak:
- Switch web Google Sign-In to full-page redirect mode (
ux_mode: 'redirect') targetinghttps://api.vipergto.com/auth/google/callback. - Because Google’s default
g_csrf_tokencookie is host-scoped (set onapp.vipergto.com, invisible toapi.vipergto.com), generate a cryptographic nonce in a.vipergto.comcookie, pass it intoinitialize({ nonce }), and verify the Google-signed nonce inside the ID token on the server.
3. Making trees fit inside browser and mobile RAM
Raw CFR solvers explode in memory if you store full unmerged game trees and duplicate EV arrays. Three design choices keep viper-engine lean enough for laptops and phones:
Suit isomorphism (1.6×–3.2× speedup, up to 71% smaller trees)
On a two-tone or monotone flop, strategically identical suits produce isomorphic chance subtrees. GameTree::build_iso shares chance subtrees across suit equivalence classes (preserving fixed board cards and both player ranges), traverses each class once, and reconstructs member values via hand permutation.
Verified on Ks 7s 2d (50 iterations, identical game values and root frequencies; exploitability matched to 3 decimals: 1.529 vs 1.528):
| Board texture | Plain tree nodes | Isomorphic tree nodes | Memory reduction | 50-iter runtime | Speedup |
|---|---|---|---|---|---|
| Two-tone flop | 448k nodes | 270k nodes | -40% | 24.8s → 15.5s | 1.6× |
| Monotone flop | 448k nodes | 129k nodes | -71% | 25.3s → 7.9s | 3.2× |
| Rainbow flop | 448k nodes | 448k nodes | 0% (expected) | unchanged | 1.0× |
Compact f32 storage & zero-CFR EV recovery
During solving, strategy sums stay in f32 (~1e-7 relative precision, two orders of magnitude finer than u16 pack quantization). For pre-solved library tables (~150 KB per flop), we store only the average strategy — never pre-computed EV tables — and recover exact per-action EVs on demand via a single avg_play_cfv evaluation pass. That cuts storage roughly in half while guaranteeing EVs remain mathematically consistent with the stored mix.
4. Measured benchmarks & cross-solver validation
Below are recorded measurements from viper-engine v0.1.5 (WASM verification runs on 25–26 Nov 2026 and native M-series release baselines):
| Benchmark | Runtime | Tree / Combos | Iterations | Measured result |
|---|---|---|---|---|
River overbet (4 sizes) (AsKd7h4c2d) |
Single-thread WASM | 63v84 combos | 500 | 60 ms · 0.008% pot expl. |
BB vs BTN flush river (Ks7s2d5c9s) |
WASM v0.1.5 | 27 nodes · 63v90 | 500 | 0.004% pot (0.0005 chips) |
Wide river (Ks7h2d5c9s) |
WASM v0.1.5 | 15 nodes · 193v121 | 300 | 0.011% pot (0.0111 chips) |
| Wide river (2 sizes + raise) | Native M-series (rayon) | 187v125 combos | — | 0.1 s · 0.045% pot |
Turn tree (chance nodes) (Ks7h2d5c) |
WASM v0.1.5 | 1,305 nodes · 49v69 | 100 | 0.131% pot |
| Flop tree (1 bet size) | Native M-series (rayon) | 457k nodes | 100 | 50 s |
For correctness, we validate against both closed-form analytic games (Clairvoyance river target 0.75P IP / 0.25P OOP) and a historical 580-node turn alignment against TexasSolver v0.2.0 (Ks7h2d5c, pot 50, stack 2,000, 50% bets), where our independent best-response evaluator measured the exported TexasSolver strategy at 0.310% pot and Viper’s strategy at 0.004% pot. Full details and downloadable inputs live on our engine validation page.
5. Honest boundaries: what still belongs offline
Local WebAssembly and mobile solving is transformative for river studies, turn spots, nodelocking, and hand-history review — where trees converge in milliseconds to seconds right on your device.
At the same time, browser tabs still face practical memory caps (typically 2–4 GB per WebAssembly linear memory) and mobile CPUs throttle under sustained multi-minute load. Massive multi-sizing flop trees or batching hundreds of flops overnight still belong on dedicated multi-core workstations or an offline solve farm.
That is why Viper GTO pairs both worlds: an offline farm pre-solves our 100bb heads-up library for instant daily drilling, while the shared local Rust/WASM/UniFFI engine handles custom spots and nodelocking right on your laptop or phone.
Want to test it yourself? Open the browser GTO solver or compare workflows on our solver comparison page.
Common questions
Why does browser multithreading require COOP and COEP HTTP headers?
After Spectre, browsers restrict SharedArrayBuffer — required for WebAssembly threads via wasm-bindgen-rayon — to cross-origin isolated documents serving Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp.
What happens if a browser or WebView does not support SharedArrayBuffer?
Viper GTO’s solver worker automatically falls back to the 468 KB single-threaded WebAssembly binary, and races thread-pool initialization against an 8-second timeout so blocked nested workers never hang a solve.
Do custom spots get uploaded to a server when solving in Viper GTO?
No. Custom postflop solves and nodelocking run locally on your device’s CPU. Only explicit cloud actions — such as signing in, saving a hand review, accessing the pre-solved library or requesting an AI coach explanation — use the network.