Skip to content

⚡ Bolt: [performance improvement] O(1) array tracking for forbidden cards - #72

Open
wavehs wants to merge 1 commit into
mainfrom
bolt-optimize-forbidden-array-1942710557587784763
Open

wavehs wants to merge 1 commit into
mainfrom
bolt-optimize-forbidden-array-1942710557587784763

Conversation

@wavehs

@wavehs wavehs commented Jun 26, 2026

Copy link
Copy Markdown
Owner

💡 What: Replaced set logic for filtering used cards in Monte Carlo inner loops with an O(1) boolean tracking array.
🎯 Why: In compute_range_vs_range_equity, forbidden = set(v_hand) | set(sampled_board) creates a new set object on every simulation iteration which causes tremendous memory allocation overhead given this loop fires millions of times.
📊 Impact: Reduces total evaluation overhead per Monte Carlo simulation significantly by avoiding runtime set() overhead in Python, leveraging direct list unrolling array lookups.
🔬 Measurement: Execute PYTHONPATH=. python evals/bench_solver.py to observe lower latencies for the range evaluation step. Test suite assertions for this edge case confirm validity.


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

…n compute_range_vs_range_equity

Replaced the dynamic instantiation of a set inside the hot loop `forbidden = set(v_hand) | set(sampled_board)` with a pre-allocated O(1) tracking boolean array `forbidden = [False] * 52`.
This drastically reduces memory allocation and dictionary overhead inside the innermost Monte Carlo evaluation block, avoiding constant `set` creations and `in` operator lookups. The mutated bits are unset dynamically after each execution to preserve memory safety.

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