Skip to content

⚡ Bolt: [performance improvement] Optimize Monte Carlo inner loop tracking & unpacking - #56

Open
wavehs wants to merge 1 commit into
mainfrom
jules-10145785771126732807-85738163
Open

wavehs wants to merge 1 commit into
mainfrom
jules-10145785771126732807-85738163

Conversation

@wavehs

@wavehs wavehs commented Jun 9, 2026

Copy link
Copy Markdown
Owner

💡 What: The optimization implements array unpacking for tuple primitives and extracts method reference to avoid attribute lookup overhead inside the hot loop. In addition, it correctly handles resetting pre-allocated array memory rather than casting it back and forth to sets inside hot iterative cycles which is slow and error-prone (TypeErrors when assigning to sets).
🎯 Why: Avoiding dynamic allocations inside heavy Monte Carlo simulations minimizes Python GC pauses and improves simulation speed. This also fixes a TypeError bug caused by inadvertently overwriting the O(1) tracking array forbidden into a python set and then attempting an array-index assignment.
📊 Impact: Considerably faster range-vs-range computations due to reduced memory churn. Fixes a crash blocking the calculation in edge cases.
🔬 Measurement: Verify changes using PYTHONPATH=. python -m pytest tests/test_solver.py.


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

- Avoid list type constructor by replacing `list(h_hand)` with `[h0, h1]` unpacking.
- Maintain array lookup for tracking forbidden cards rather than converting it to a Python set.
- Extract `self.evaluator.evaluate` to a local function reference prior to the loop.

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