⚡ Bolt: optimize random number generation for high density#57
⚡ Bolt: optimize random number generation for high density#57babelman97 wants to merge 1 commit into
Conversation
Optimized the random number generator in random.html by implementing a hybrid sampling strategy. For high-density requests (>50% of range), the generator now uses exclusion-based sampling paired with a Fisher-Yates shuffle. This prevents the performance collapse associated with the 'Coupon Collector's Problem' in the original rejection sampling logic. Measured impact: ~7.8x speedup (approx. 2119ms to 269ms) for 999,990 unique numbers in a 1,000,000 range. Co-authored-by: babelman97 <186798789+babelman97@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: Implemented a hybrid sampling strategy in `random.html`. Added a Fisher-Yates shuffle helper and conditional logic to switch between rejection sampling (for sparse requests) and exclusion sampling (for dense requests).
🎯 Why: The original implementation used rejection sampling exclusively. As the requested count approaches the total range size, the probability of generating a new unique number drops significantly, causing the loop to run millions of redundant iterations.
📊 Impact: Reduces execution time by ~87% for high-density requests (e.g., 999,990 numbers in a 1,000,000 range), improving performance from ~2.1s to ~0.27s.
🔬 Measurement: Benchmarked using Playwright by executing `generateRandomNumbers()` within a browser page evaluate block and measuring the delta via `performance.now()`. Verified functional correctness (uniqueness, count, range) for all sampling paths.
PR created automatically by Jules for task 11560059252563854543 started by @babelman97