Codepen demo (https://codepen.io/nicoptere/pen/dygBpPg ) manipulating pixels takes ~3x more time in Nightly compared to Chrome
Categories
(Core :: JavaScript Engine, task, P3)
Tracking
()
People
(Reporter: mayankleoboy1, Unassigned)
References
(Blocks 1 open bug, )
Details
Attachments
(1 file)
|
4.24 KB,
text/html
|
Details |
Go to https://codepen.io/nicoptere/pen/dygBpPg
Chrome: https://share.firefox.dev/3s2iNl5 (2 seconds)
Nightly: https://share.firefox.dev/43ZkNHO (6 seconds)
| Reporter | ||
Comment 1•3 years ago
|
||
Comment 2•3 years ago
|
||
This is spending most of its time under isNaN. It's called with an object so ToNumber does slow conversions to primitive.
Updated•3 years ago
|
| Reporter | ||
Comment 3•2 years ago
|
||
Latest profile : https://share.firefox.dev/48CqVsQ (6s)
| Reporter | ||
Comment 4•1 year ago
|
||
Latest profile: https://share.firefox.dev/4htDsDm (6s)
Comment 5•1 year ago
|
||
ToNumber(val) is implemented as +val. It wouldn't be too hard to add a case to UnaryArithIRGenerator that handles objects. We'd have to guard the shape / proto chain to ensure that valueOf and Symbol.toPrimitive don't exist, but it would still be much faster than hitting the fallback.
Comment 6•1 year ago
|
||
Correction: we have to make sure that looking up valueOf finds the expected native function on Object.prototype, (and that Symbol.toPrimitive doesn't exist).
I poked at this for fifteen minutes, but it was a little fiddly, so I gave up. In particular, it's unlikely that ToNumber will only see objects with a single shape, and I don't immediately see a good way to implement a fast megamorphic version of this.
Comment 7•1 year ago
|
||
Jan and I chatted briefly about this. After tracing it through, we realized that actually +{} first calls valueOf (which returns the object itself), then calls toString (which returns [Object object]), then converts that to a number (which is NaN).
If we had a flag on shapes that indicated whether an object defined valueOf / Symbol.toPrimitive / toString, then we could have a megamorphic IC that would walk the proto chain until it found an object with that flag set, guard that that object was Object.prototype, and (either via explicit guards or some sort of fuse) guard that the valueOf and toString functions have their original values. If all those guards succeeded, we could simply return NaN.
This is quite a bit of work, so I don't think it's worth implementing unless we keep seeing time in ToNumber in workloads we care about.
Description
•