Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
What's the performance penalty in calling Object.setProtoytypeOf() in the following code?

I have been hearing quite a lot that Object.setPrototypeOf() in JavaScript is not a good thing to do. It reduces optimizations and lowers down the performance of an application.

Specifically, it reduces some inline caches and fast prototype property lookups made for a given object.

Now, I have one question in my mind that doesn't seem to have been answered anywhere online. That is:

If Object.setPrototypeOf() removes inline caches and wastes other optimizations, then this would only be applicable, and rigorously true, when it's called multiple times while an application is running. For e.g. if I have an object o and I, let's say, change its [[Prototype]] on click of a button, then this would be the bad thing.

However, I don't see any issue whatsoever, in doing the following thing:

function Parent() {
    this.a = 1;
}

Parent.prototype.helloParent = function() {
    console.log('Parent.');
}

function Child() {
    this.b = 2;
}

Child.prototype.helloChild = function() {
    console.log('Child.');
}

Object.setPrototypeOf(Child.prototype, Parent.prototype);

Two constructor functions Child() and Parent() are created, and then Parent.prototype is set as the prototype of Child.prototype. This prototype mutation via Object.setPrototypeOf() is done immediately before any other code is run, so perhaps once the first property lookups on Child instances are performed, the JS engine could optimize their property accesses.

I couldn't understand exactly what might be the performance issue with this code specifically, assuming that Object.setPrototypeOf() is called in the application only in this way.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!