Skip to content

⚡ Bolt: [performance improvement] inner loop optimizations for compute_range_vs_range_equity - #71

Open
wavehs wants to merge 1 commit into
mainfrom
bolt-solver-equity-opt-1599781306363506516
Open

wavehs wants to merge 1 commit into
mainfrom
bolt-solver-equity-opt-1599781306363506516

Conversation

@wavehs

@wavehs wavehs commented Jun 25, 2026

Copy link
Copy Markdown
Owner

💡 What: Implemented multiple micro-optimizations inside the hot loop of compute_range_vs_range_equity, including:

  • Replaced random.sample over a filtered array with random.choice checked against an O(1) boolean array.
  • Avoided replacing the tracking boolean array (forbidden) with a set, which caused an assignment TypeError bug.
  • Hoisted method references like self.evaluator.evaluate outside the for loop to avoid property lookups.
  • Avoided the list(v_hand) constructor in favor of inline array building [v0, v1] + full_board.

🎯 Why: During large-scale Monte Carlo equity calculations (millions of evaluations), avoiding dynamic set and list constructions or unnecessary object instantiation drastically decreases simulation time. Additionally, this prevents a regression where forbidden was reassigned from an array to a set, crashing the simulation entirely on the first reset attempt.

📊 Impact: Simulation latency target was significantly hit under standard evaluation metrics, increasing the number of evaluations the CPU can push out within the target 500ms bounds.

🔬 Measurement: Verify using PYTHONPATH=. python evals/bench_solver.py and reviewing the latency improvements, or running pytest tests/ -k compute_range_vs_range_equity to confirm the fix.


PR created automatically by Jules for task 1599781306363506516 started by @wavehs

…e_range_vs_range_equity

Fixed a critical regression causing a TypeError during Monte Carlo simulations where an O(1) boolean lookup array was inadvertently overwritten by a Python set. Optimized the hot evaluation loop by:
- Replacing `random.sample` with a `while` loop drawing from `random.choice` paired with O(1) membership checks.
- Extracting method references outside the loop (`evaluate = self.evaluator.evaluate`).
- Switching to manual tuple unpacking and array construction over generic `list()` constructors.

Co-authored-by: wavehs <156133648+wavehs@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant