GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||
GeezerVison is showing github.com — util: improve util inspect performance by BridgeAR · Pull Request #22503 · nodejs/node Conversation
Member
This significantly improves the inspection performance for all array This also moves some code out of the main function to reduce the It also adds a specific boxed primitives c++ function to reduce the I also reduced the runtime for the util benchmarks as they were significantly Intermediate benchmark results:Checklist
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
BridgeAR
force-pushed
the
improve-util-perf
branch
from
acb806d to
2224329
Compare
|
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Would it be faster to do this in javascript somehow? For example: typeof arg === 'object' && arg !== null && arg.constructor === String ?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I did not test it but I would not want to use it as it's not a safe check. Someone could easily manipulate the constructor.
const s = new String('test') s.constructor = Number
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Alright, how about:
if (typeof arg === 'object' && arg !== null && Object.prototype.toString.call(arg) === '[object String]')
? Object.prototype.toString could even be cached at startup in case someone overrides it later on.
The only issue would be symbols and big integers as they don't have constructors that return object types, but at least maybe we could speed up the other type checks if this js method ends up being faster or avoid crossing the C++<->js boundary entirely if we place the symbol and bigint checks last.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That is also not a safe check:
const a = new String('test') a[Symbol.toStringTag] = 'Foo' console.log(Object.prototype.toString.call(a)) // '[object Foo]'
I'll move the bigint check in the C++ function down and I'll see if I can work around the performance penalty. Do you expect a lot of people using boxed primitives? Because for all other cases there are now less calls to C++ than before.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Seems like the main regression came due to moving the functionality to an extra function. It's probably not inlined anymore as other code is hotter and the main function is already big. I moved it back in to address the performance regression.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@BridgeAR 👆 Ideally this helper should have a JS form (that calls it) exposed on util.types like the other isNumberObject, etc.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That is automatically the case. But good that you bring it up! I'll move this to an individual commit that also adds documentation for the function.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm not sure I'd call |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Ok. But then I'd assume log appending will generate I/O that will shadow the CPU work by |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This is goodness for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Then this needs reframing. Call it |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@refack The PR here doesn't appear to make things any harder to reason about, simplifies an expensive set of operations, and opens the possibility of carrying over useful helpers to Would it help if this PR moved/saved any of the source refactoring and cleanup bits for another PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@refack I actually tried to reduce the overall complexity while significantly improving the performance.
Definitely! I want to do that as well. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I just pushed two new commits: one to document the new function and one to address the boxed regression.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@nodejs/util PTAL |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Should this be backported to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
PR-URL: nodejs#22503 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
This significantly reduces the benchmark runtime. It removes to many variations that do not provide any benefit and reduces the iterations. PR-URL: nodejs#22503 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
This significantly improves the inspection performance for all array types. From now on only the visible elements cause work instead of having to process all array keys no matter how many entries are visible. This also moves some code out of the main function to reduce the overall function complexity. PR-URL: nodejs#22503 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Backport-PR-URL: #23039 PR-URL: #22503 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
This significantly reduces the benchmark runtime. It removes to many variations that do not provide any benefit and reduces the iterations. Backport-PR-URL: #23039 PR-URL: #22503 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
This significantly improves the inspection performance for all array types. From now on only the visible elements cause work instead of having to process all array keys no matter how many entries are visible. This also moves some code out of the main function to reduce the overall function complexity. Backport-PR-URL: #23039 PR-URL: #22503 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.