Optimizing The Bubbles Screensaver, Again

I already optimized this once before, but I’ve found a much better collision checking system. The new bubbles screensaver now supports 70 bubbles, up from 50.

The new system

Here’s how it works: it sorts the bubbles based on their X position and loops through the bubbles. For every bubble, it looks backwards in the list, checking against each bubble until it finds one which is out of range to collide. This significantly reduces the number of checks needed. I also borrowed some ideas from C and avoided adding and deleting items from lists.

Comparing both versions with 40 bubbles, the old method averages around 750 collision checks and the new method around 250.

Leave a comment

Your email address will not be published. Required fields are marked *

Your data is processed in accordance with my privacy policy. Comments are manually approved and may take a while to appear.