Self-host Array.prototype.sort with comparator function

RESOLVED DUPLICATE of bug 715181

Status

()

Core
JavaScript Engine
RESOLVED DUPLICATE of bug 715181
6 years ago
5 years ago

People

(Reporter: jandem, Unassigned)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [js:t])

(Reporter)

Description

6 years ago
Sunspider string-tagcloud calls sort on a large array with a comparator function:

    tagInfo.sort(function(a, b) { if (a.tag < b.tag) { return -1; } else if (a.tag == b.tag) { return 0; } else return 1; });

Here we spend a lot of time pushing frames, type-checking arguments, entering JM/Ion, etc etc. It would be awesome if we could self-host this case since the JITs can do all these operations much faster.

I hope this will win a few ms on string-tagcloud, it's a lot considering sunspider runs in < 200 ms nowadays.
I'll look into implementing sort next week. The problem is that properly implementing it, as well as any other Array methods that mutate an, existing or new, Array, requires setting values without invoking setters.

There are horrible tests involving setters on Array.prototype for that in test262.

Comment 2

6 years ago
(In reply to comment #1)
> There are horrible tests involving setters on Array.prototype
> for that in test262.

Point me to those tests?  The spec language is a "sequence of calls to the [[Get]], [[Put]], and [[Delete]] internal methods" and says nothing about behavior for setters on Array.prototype.  Actually, it specifically says behavior is implementation-defined if the prototype [[HasProperty]] for some j where 0 <= j < arr.length.  That doesn't necessarily mean we could change our behavior, but it seems the spec isn't the barrier to change, if indeed there are any barriers.
(In reply to Jeff Walden [:Waldo] (remove +bmo to email) from comment #2)
> (In reply to comment #1)
> > There are horrible tests involving setters on Array.prototype
> > for that in test262.
> 
> Point me to those tests?  The spec language is a "sequence of calls to the
> [[Get]], [[Put]], and [[Delete]] internal methods" and says nothing about
> behavior for setters on Array.prototype.  Actually, it specifically says
> behavior is implementation-defined if the prototype [[HasProperty]] for some
> j where 0 <= j < arr.length.  That doesn't necessarily mean we could change
> our behavior, but it seems the spec isn't the barrier to change, if indeed
> there are any barriers.

Never mind, I thought the fact that Array.prototype.map uses [[DefineOwnProperty]] (in step 8.c.iii) meant that all Array-mutating methods would do that.

All the better: Array.prototype.sort should be fully implementable right now, then.
Whiteboard: [js:t]
This is a duplicate of bug 715181?
Yes, it is, thanks
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 715181
You need to log in before you can comment on or make changes to this bug.