-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: inline Array
operations in FreeList
methods
#37649
base: main
Are you sure you want to change the base?
Conversation
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 <[email protected]>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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/
|
@@ -9,18 +10,29 @@ class FreeList { | |||
this.name = name; | |||
this.ctor = ctor; | |||
this.max = max; | |||
this.list = []; | |||
this.list = ObjectSetPrototypeOf([], null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 thelist
tonull
so that OrdinarySetWithOwnDescriptor doesn’t walk up the prototype chain.This avoids depending on user code not mutating
%Array.prototype%.pop
and%Array.prototype%.push
.Refs: #36565
Refs: #36600
/cc @aduh95 @Lxxyx