|
|
|
|
|
by jonnycat
667 days ago
|
|
One interesting note on this approach is that the author suggests using a "fast" sorting algorithm like mergesort/quicksort as the sorting algorithm for best performance. But in practice, you may get better performance from a "worse" sorting algorithm: insertion sort. The reason is that objects in collision detection systems tend to move relatively small steps between frames, meaning you can keep lists from the previous frame that are already mostly sorted. For sorting these mostly sorted lists, insertion sort tends towards O(n) while Quicksort tends towards O(n^2)! |
|
> Let’s look at the sort step, which is the bottleneck of the algorithm according to the analysis.
> You can see that most of the time, the sort does nothing at all! The list is almost always already sorted from the previous frame.
> Even when it becomes unsorted, it usually just takes a couple of swaps to be sorted again.
> Here’s insertion sort in action: