Like it probably doesn't matter if you're sorting 10k entries, but when you're sorting several gigabytes it really does.
Like it probably doesn't matter if you're sorting 10k entries, but when you're sorting several gigabytes it really does.
The actual implementation in Toit does depth first, so eg. the leftmost 8,8->16 merge is done as soon as the 8-element ranges are ready.
Collecting those nine elements looks terrible for locality.
Funnelsort is a cache oblivious variant of merge sort which is provably cache optimal in some sense. I haven't tried implementing it.
https://en.wikipedia.org/wiki/Introsort#Implementations
And heapsort has terrible cache behaviour.
Eventually I realized I was running out of desk space, so I started merging little stacks of around equal size.
So the base case wasn’t 1 element, but that’s conventional for actual implementations. And the splitting wasn’t quite recursive I guess. But partial credit at least.
This cost model is an important reason to merge bottom up, from sorted subsequences, without arbitrary splitting that can add work but not reduce it.
I think back on it with a certain amount of nostalgia now, but it was a stupid way to do operations, even at the time, They had invested big in computers in the 70's and were still maintaining the same tech stack in the early 00's when I worked there.