lib: inline Array operations in FreeList methods#37649
lib: inline Array operations in FreeList methods#37649ExE-Boss wants to merge 1 commit intonodejs:mainfrom
Array operations in FreeList methods#37649Conversation
|
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/957/ Benchmark results still show regression: |
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
f29ec6b to
326ddd9
Compare
| this.list.pop() : | ||
| ReflectApply(this.ctor, this, arguments); | ||
| const { list } = this; | ||
| const { length } = list; |
There was a problem hiding this comment.
You might see if avoiding the destructuring assignments helps with the perf regressions. I know at one point it was significantly slower.
|
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/959/ |
| this.ctor = ctor; | ||
| this.max = max; | ||
| this.list = []; | ||
| this.list = ObjectSetPrototypeOf([], null); |
There was a problem hiding this comment.
@ExE-Boss I see in #36600 you using SafeArray:
https://github.com/ExE-Boss/node/blob/283189fcce72f98f55d335292db0b3b77a252279/lib/internal/freelist.js#L13
To me it seems the intention is the same to ensures that the array used is not affected by any potential modifications to the standard Array.prototype in user code or other libraries. I think it's great, and this is about maintaining encapsulation and avoiding unexpected side effects caused by changes to global prototypes.
Could you please kindly clarify what's the difference?
There was a problem hiding this comment.
The difference is largely performance, as #36600 has a -91% perf regression, and this only has a -90%.
This inlines a simplified behaviour of
%Array.prototype.pop%and%Array.prototype.push%inFreeList’s methods and sets the prototype of thelisttonullso that OrdinarySetWithOwnDescriptor doesn’t walk up the prototype chain.This avoids depending on user code not mutating
%Array.prototype%.popand%Array.prototype%.push.Refs: #36565
Refs: #36600
/cc @aduh95 @Lxxyx