buffer: make FastBuffer safe to construct#36587
Conversation
|
Benchmark results are not as good as the one I got locally, that might be related to using a different OS / architecture, not sure 🤔 @mscdex FYI Details |
|
From what I can see based on the architecture I have at my disposal, this PR is neutral for performance on |
|
I'm inclined to believe Jenkins on this one as this is literally the same behavior as before. If anything, I'd expect a minor perf hit because V8 may be able to optimize calling default constructors of built-in types. |
Except it doesn't use |
I don't follow. What I'm referring to is the change in this PR: From an implicit, inherited constructor: class FastBuffer extends Uint8Array {}To an explicit constructor that passes the exact same parameters: class FastBuffer extends Uint8Array {
// eslint-disable-next-line no-useless-constructor
constructor(bufferOrLength, byteOffset, length) {
super(bufferOrLength, byteOffset, length);
}
}Neither of these should invoke anything |
|
@mscdex Except that a missing constructor in a derived class is equivalent to: constructor(...args) { super(...args) }And the spread operator invokes the delete Array.prototype[Symbol.iterator];
new (class extends Object {})();You’ll get: Until tc39/ecma262#2216 is implemented. |
|
I think if this is going to be merged, we should have at least a code comment describing why this is being done this way. I'm +0 on this since it doesn't really seem to change much, at least with the |
|
Relevant spec section: https://tc39.es/ecma262/#sec-runtime-semantics-classdefinitionevaluation
Note that there's also a difference because the |
Using an explicit constructor is necessary to avoid relying on `Array.prototype[Symbol.iterator]` and `%ArrayIteratorPrototype%.next`, which can be mutated by users.
9e816db to
657c772
Compare
|
Force pushed to fix the commit message. |
|
Landed in bd6f230...0187716 |
Default constructor iterates over the argument when calling the
superconstructor, we can get better result by passing an exact number of arguments on Apple Silicon processors.Benchmark I run locally
Related Issues
Refs: #36428
Refs: #36532
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes