Closed Bug 1643750 Opened 8 months ago Closed 7 months ago

Optimize Object.prototype.toString for primitives

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
mozilla79
Tracking Status
firefox79 --- fixed

People

(Reporter: tcampbell, Assigned: tcampbell)

Details

Attachments

(1 file)

This is a bit silly, but there is noticeable time on sites like reddit spent converting primitives to objects in order to call toString.

eg.

function c(e) {
  return "[object Object]" === Object.prototype.toString.call(e);
}

We currently handle this by calling obj_toString but this is allocating objects. As a short-term fix, I'll add a fast path there. In the future with WarpBuilder, we should be able to do a better job.

While this is a bit silly, the code does come up in the wild. We avoid
allocating objects for primitives we can can show that the global prototypes
were not tampered with.

Here is a patch that improves that case. It became more complex than I wanted though. In future it would be good to have a transpile-able IC

Pushed by tcampbell@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/8c3873698dcb
Optimize Object.prototype.toString for primitives. r=jandem
Status: NEW → RESOLVED
Closed: 7 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla79
You need to log in before you can comment on or make changes to this bug.