Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda