⚡ Bolt: optimize unique random number generation#102
Conversation
Implemented a hybrid sampling algorithm in random.html to address performance collapse at high densities. Added Sparse Fisher-Yates shuffle for samples >= 50% of range and improved UI responsiveness for large result sets. - Replaced rejection sampling with Sparse Fisher-Yates (Map-based) for high density - Switched from innerText to textContent for faster DOM updates - Added input validation and a 10M range safety cap - Enhanced CSS for result container with scrolling and overflow handling - Logic speedup: ~6.5x (400ms vs 2600ms for 1M range) - Total UI speedup: ~2.6x (5.5s vs 14.5s total time) Co-authored-by: babelman97 <[email protected]>
|
👋 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.htmlfor unique random number generation.Set.Map.innerTexttotextContent.max-heightandoverflow-y: autoto the results container.🎯 Why
Rejection sampling suffers from the "coupon collector's problem" where collisions become extremely frequent as the sample count approaches the range size, leading to$O(N^2)$ or worse performance. This caused the browser to hang for several seconds when generating large unique sets.
📊 Impact
🔬 Measurement
Verified using a Playwright benchmarking script measuring
performance.now()for internal logic and total time until the DOM reflects the results. Screenshotrandom_optimized.pngshows the new scrollable UI.PR created automatically by Jules for task 2622278185721710192 started by @babelman97