Reputation: 21881
Does the size of an array object element affect the performance of sorting the array?
I suspect the answer is no, because only memory pointers (if I get it correctly) are sorted. But I would be grateful if someone who knows will confirm/reject/explain this.
The property by which to sort contains a number: 1,2,3 etc..
Example of the two arrays:
const arr1 = [{blob: {/*huge object here*/}, order: 1}, /*similar objects*/]
const arr2 = [{smallObject: {foo: 'bar'}, order: 1}, /*similar objects*/]
// sorting like this:
arr.sort((a,b)=> a.order > b.order ? 1 : -1)
Upvotes: 1
Views: 230
Reputation: 138267
No. Pointers are the only way to represent dynamic nested structures efficiently, so the "size" of objects won't affect the sorting, as just pointers have to get swapped.
The size of the array however does affect the sorting speed, if there are more elements you have to sort more.
Upvotes: 3