Open apblack opened 7 years ago
Before doing this, it's probably worth checking that it actually yields a speed increase!
Folk wisdom says that methods on a prototype can actually be faster than those on the object. And the check for initialization is likely to be optimized away by the Javascript JIT.
Moreover, having some methods on the object and others on the prototype might inhibit the important optimization of moving all methods to the prototype, except for those that access variables in an enclosing scope.
An accessor method for
v
compiled for an object must check for an uninitialized variablev
before returning (even in a module object, because a method used in the initialization of another fieldt
might accessv
before it is initialized.)However, once this check succeeds, the accessor method could be overwritten with a new one that no longer does the check.
Currently, the check persists for ever. This is correct, but changing the accessor might bring a speed increase, particularly if the non-checking accessor is on the prototype, and the checking accessor on the object itself.