Relational comparison of objects is slower than v8

NEW
Unassigned

Status

()

Core
JavaScript Engine: JIT
P5
normal
5 years ago
3 months ago

People

(Reporter: jandem, Unassigned)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

5 years ago
Octane-box2d has a function that does this:

    x.proxyA = t < m ? t : m;
    x.proxyB = t >= m ? t : m;

t and m are both objects that don't have a valueOf/toString hook, so this effectively comes down to comparing "[object Object]" and the first comparison is always false, the second always true...

This is pretty stupid but if Ion could see we have objects with the default valueOf/toString properties it could probably fold this.

Box2d does this about 40,000 times, for the (similar) micro-benchmark below I get 54 ms for us, 30 ms for v8.

function f() {
    var o1 = {}, o2 = {};
    var res = false;
    var t = new Date;
    for (var i=0; i<40000; i++) {
	res = o1 < o2;
	res = o1 >= o2;
    }
    print(new Date - t);
    return res;
}
f();
(Reporter)

Comment 1

5 years ago
(In reply to Jan de Mooij [:jandem] from comment #0)
> Box2d does this about 40,000 times, for the (similar) micro-benchmark below
> I get 54 ms for us, 30 ms for v8.

With the patch in bug 966264 I get 29 ms.
Priority: -- → P5
(Reporter)

Updated

3 months ago
Assignee: jdemooij → nobody
Status: ASSIGNED → NEW
You need to log in before you can comment on or make changes to this bug.