This certainly is a challenge and there are many ways to approach it. The easiest of them all is to find a computer with as much RAM as possible and the fastest CPU. Throwing money at a problem certainly will help you solve many problems. But not all of us have this luxury.
The second method is to make sure you have a decent enough machine, and divide the objects in chunks that can fit in memory. It may take a while to sort them all but it will get done eventually. This works great, if you are not in a hurry.
If you are trying to sort that much to display it on the DOM you are probably doing it wrong.
Sometimes there are no tricks, just use plain old boring technologies to solve your problems.