Closed Bug 1131523 Opened 9 years ago Closed 9 years ago

Handle property accesses on object-or-primitive better

Categories

(Core :: JavaScript Engine: JIT, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: jandem, Assigned: jandem)

References

Details

(Keywords: perf)

Noticed this while investigating bug 1131099. Lodash does things like this:

  isLarge = isCommon && length >= 200,
  seen = isLarge && createCache(),

The result is that |seen| has a TypeSet that includes object + boolean and we don't use a GetProperty IC. Probably the most robust thing to do here is to inspect the Baseline ICs and (fallibly) unbox to object if we've never actually seen a primitive for this property access.

A quick workaround for this makes us 4-5x faster on those tests.
John, we'll probably want to fix this in lodash too as it will affect older FF releases and probably other JS engines...
What would be the workaround?
(In reply to John-David Dalton from comment #2)
> What would be the workaround?

I guess assigning a null value in the !isLarge case, i.e. transforming the && into a ternary:

seen = isLarge ? createCache() : null;

Jan, can you confirm please?
Flags: needinfo?(jdemooij)
Yes, this gives a massive boost – http://jsperf.com/array-object-unique/3#chart=bar
Blocks: 1159629
Clearing the needinfo. This is on the TODO list, but keeping all these requests unnecessarily clutters my review queue and is a bit demotivating.
Flags: needinfo?(jdemooij)
Keywords: perf
Oops, I thought I needinfo'd myself to fix this but I didn't.

(In reply to Benjamin Bouvier [:bbouvier] from comment #3)
> Jan, can you confirm please?

Yes that looks fine and based on comment 4 it helped a lot :)
The follow-up patch in bug 1169611 fixed this. Lodash (older version) improvement:

http://arewefastyet.com/#machine=29&view=single&suite=misc&subtest=bugs-1131099-lodash1
http://arewefastyet.com/#machine=29&view=single&suite=misc&subtest=bugs-1131099-lodash2
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.