Post

TIL: Prefer `Float64Array` over `Array<number>` when you care about sorting. Sorting the former is a lot faster.

1 repost19 likes

This might seem like it so fast that it does not matter... but... Hermes.

And here is the Hermes graph. Note that the actual numbers are not representative since this was run on iOS simulator on a MacBook M5. In reality old Android phones are at least 5x slower.

Yeah, Float64Array.sort is easy mode: with no args, we call straight into the runtime and run std::sort on the backing store (github.com/v8/v8/blob/m...). To get Array.sort close to this speed, you'd have to already have the right backing store, and then inline the comparator somehow.

Any reason to not use TimSort for TypedArray? (who should I cc?)

Also, unfortunately `TypeArray.prototype.sort` does not use TimSort... Not sure why???