lib: add TypedArray to the primordials#32127
Conversation
|
For some reason this seems to have some regressions at least in the buffer-fill benchmarks here: |
|
Let's revisit after V8 8.0+ lands on master. The overhead should be fixed |
Is it currently possible to at least run these specific benchmarks with V8 8.x to verify the issues are resolved there? |
|
you can try with this canary build (V8 8.1): https://nodejs.org/download/v8-canary/v14.0.0-v8-canary20200121fda488ae67/ |
|
canary-base vs. canary-base + this change: |
This also makes it possible to use Symbol methods and getters.
0a11233 to
95b07ea
Compare
|
New results: |
|
/cc @nodejs/v8 If I understood https://v8.dev/blog/v8-release-80#optimizing-higher-order-builtins correctly, this change shouldn't affect performance anymore. But we still see a significant difference between these two cases: // 1
const TypedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
const TypedArrayFill = TypedArrayPrototype.fill;
TypedArrayFill.call(buffer, value);
// 2
const ReflectApply = Reflect.apply;
function uncurryThis(func) {
return (thisArg, ...args) => ReflectApply(func, thisArg, args);
}
const TypedArrayPrototypeFill = uncurryThis(TypedArrayFill);
TypedArrayPrototypeFill(buffer, value); |
|
What version of V8 are the newest results based on? |
|
The one we have on master, 8.3. |
| const desc = Reflect.getOwnPropertyDescriptor(src, key); | ||
| if (typeof desc.value === 'function') { | ||
| desc.value = uncurryThis(desc.value); | ||
| } else if (typeof desc.get === 'function') { | ||
| desc.value = uncurryThis(desc.get); | ||
| delete desc.get; | ||
| delete desc.set; | ||
| } | ||
| Reflect.defineProperty(dest, newKey, desc); |
There was a problem hiding this comment.
We should probably also save the setter if it exists.
| const desc = Reflect.getOwnPropertyDescriptor(src, key); | |
| if (typeof desc.value === 'function') { | |
| desc.value = uncurryThis(desc.value); | |
| } else if (typeof desc.get === 'function') { | |
| desc.value = uncurryThis(desc.get); | |
| delete desc.get; | |
| delete desc.set; | |
| } | |
| Reflect.defineProperty(dest, newKey, desc); | |
| const desc = Reflect.getOwnPropertyDescriptor(src, key); | |
| let setterDesc; | |
| if (typeof desc.value === 'function') { | |
| desc.value = uncurryThis(desc.value); | |
| } else if (typeof desc.get === 'function') { | |
| desc.value = uncurryThis(desc.get); | |
| if (typeof desc.set === 'function') { | |
| setterDesc = { value: uncurryThis(desc.set), enumerable: desc.enumerable }; | |
| } | |
| delete desc.get; | |
| delete desc.set; | |
| } | |
| Reflect.defineProperty(dest, newKey, desc); | |
| if (setterDesc) { | |
| Reflect.defineProperty(dest, `${newKey}Setter`, desc); | |
| } |
8ae28ff to
2935f72
Compare
|
Related to #36016. |
|
This needs a rebase. |
|
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
Closes: nodejs#32127 PR-URL: nodejs#36329 Fixes: nodejs#32127 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This also makes it possible to use Symbol methods and getters.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes