Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The Object performance are 5-100 times slower than Chrome. Array is a bit slow, map is faster, uint32array are 5 times faster.

115 views
Skip to first unread message

罗勇刚(Yonggang Luo)

unread,
Mar 7, 2016, 4:43:20 PM3/7/16
to Mozilla Platform
My conclution: we really need improve the performance of Object,
cause that's the most frequently used Thing.
```code

performanceButton.onclick = function () {
let startTime = Date.now()
ChromeSamples.setStatus(`Start performance testing at time ${startTime}`);
function testArray(count) {
let startTime = Date.now()
let a = []
for (let i = 0; i < count; ++i) {
a[i] = i + 1
}
return Date.now() - startTime
}
function testObject(count) {
let startTime = Date.now()
let a = {}
for (let i = 0; i < count; ++i) {
a[i] = i + 1
}
return Date.now() - startTime
}
function testObjectSingle(count) {
let startTime = Date.now()
let a = {}
for (let i = 0; i < count; ++i) {
a[0] = i + 1
}
return Date.now() - startTime
}
function testMap(count) {
let startTime = Date.now()
let a = new Map()
for (let i = 0; i < count; ++i) {
a.set(i, i + 1)
}
return Date.now() - startTime
}
function testUint32Array(count) {
let startTime = Date.now()
let a = new Uint32Array(count)
for (let i = 0; i < count; ++i) {
a[i] = i + 1
}
return Date.now() - startTime
}
setTimeout(function () {
let count = 10000000
let testResult = {
array: testArray(count),
object: testObject(count),
objectSingle: testObjectSingle(count),
map: testMap(count),
uint32Array: testUint32Array(count),
}
ChromeSamples.setStatus(`Start performance ending at time
${JSON.stringify(testResult)}`);
})
}
```
Firefox:
Start performance ending at time Start performance ending at time
{"array":340,"object":4762,"objectSingle":2699,"map":5151,"uint32Array":29}
Chrome:
Start performance ending at time
{"array":215,"object":614,"objectSingle":49,"map":6232,"uint32Array":100}

--
此致

罗勇刚
Yours
sincerely,
Yonggang Luo

Boris Zbarsky

unread,
Mar 8, 2016, 2:40:43 PM3/8/16
to
On 3/7/16 4:42 PM, 罗勇刚(Yonggang Luo) wrote:
> My conclution: we really need improve the performance of Object,

Please file a bug on JS engine.

That said, some of your results are a bit suspect. For example, the
"testObjectSingle" number for Chrome shows that each set takes 4.9ns on
your hardware. On mine, it takes 0.7ns (my number there is 7ms, not
49ms). 0.7ns is about how long that test takes if I comment out the
loop body entirely. So what that test is really measuring is whether
the JIT manages to figure out that the earlier sets are dominated by
later ones and optimize them all out entirely. That's a good thing to
be able to do, but has nothing to do with the performance of property
sets per se.

For what it's also worth, the Array test runs faster than in Chrome (by
almost 3x) for me on Mac, while the uint32Array one runs slower by 3x...

The testObject test is definitely worth looking into, though I expect
it's caused by bug 1091978: profile shows we keep missing in the
SetProperty IC and having to do a vmcall.

-Boris

Nicholas Nethercote

unread,
Mar 8, 2016, 4:38:31 PM3/8/16
to Boris Zbarsky, dev-platform
On Wed, Mar 9, 2016 at 6:40 AM, Boris Zbarsky <bzba...@mit.edu> wrote:
>
> That said, some of your results are a bit suspect.

Indeed, microbenchmarks like these are surprisingly difficult to write
well, and they often end up measuring something other than what the author
intends.

Microbenchmarks that are extracted from real programs -- e.g. pulling out a
"kernel" of hot code, possibly simplified -- are likely to be more useful,
though it's still possible to get them wrong too :)

Nick

Jan de Mooij

unread,
Mar 9, 2016, 12:18:55 AM3/9/16
to luoyo...@gmail.com, Mozilla Platform
On Mon, Mar 7, 2016 at 10:42 PM, 罗勇刚(Yonggang Luo) <luoyo...@gmail.com>
wrote:

> My conclution: we really need improve the performance of Object,
> cause that's the most frequently used Thing.
>

I agree plain objects are among "the most frequently used objects", but
here you're using them as arrays and that's not how plain objects are
typically used. Performance of setting indexed properties is mostly
unrelated to setting named properties.

That said, it's a valid performance issue so I filed bug 1254436 [0].
Thanks for reporting this. Next time you run into a JS (performance) issue,
please file a bug in the 'Core: JavaScript Engine' component :)

Thanks,
Jan

[0] https://bugzilla.mozilla.org/show_bug.cgi?id=1254436
> _______________________________________________
> dev-platform mailing list
> dev-pl...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
0 new messages