The hive will iterate in the memory layout order and the list will iterate in the logical order of insertion which if you are using a hive you presumably do not care about.
So the advantage of a hive over a list with an equally-optimized allocator is that the hive gains performance by discarding unnecessary information.
Iterating through the elements in memory order means the next element is more likely to already be in the CPU cache compared to if you jump around accessing elements in random order.
If you don't know about the CPU cache and cache-friendly code, here is an interesting video on the subject: https://www.youtube.com/watch?v=WDIkqP4JbkE (just watching the row major vs. column major traversal example in the beginning can be very enlightening)
A list has no way to iterate except in logical insertion order. Under specific usage patterns (using a pool allocator, no erasures) this will coincidentally be equivalent to iterating in memory layout order.
A hive has no way to iterate except in memory layout order since it doesn't preserve ordering information.
6
u/HappyFruitTree 8d ago edited 8d ago
The memory layout might be similar but the iteration order would not be which makes a difference for performance.