Uh oh!
There was an error while loading. Please reload this page.
util: improve inspect performance - #14881
Conversation
There was a problem hiding this comment.
a long series of if - else if - else if statements can also be formatted as a switch (true) { ... } (note that switch does a strict comparison, ie matches not truthy but true). Strictly a layout issue, otherwise completely equivalent, both O(n) in the number of tests.
There was a problem hiding this comment.
I you prefer that I can change it, otherwise I would just keep it as is.
addaleax
left a comment
There was a problem hiding this comment.
This is great work, thank you!
There was a problem hiding this comment.
ctx.seen = [...ctx.seenSet]?
Also, I, personally, would be fine with having seen just be a getter/setter pair.
There was a problem hiding this comment.
I feel like this could just be turned into a Set as well
There was a problem hiding this comment.
I tried that and it was actually a bit slower in my benchmarks. When 6.1 lands I might have another look at it.
There was a problem hiding this comment.
This really sounds like it would return a boolean ;)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
addaleax
commented
Aug 17, 2017
Also, sorry for the merge conflict, I fixed Evan’s nit while landing my PR. |
BridgeAR
commented
Aug 17, 2017
There was a problem hiding this comment.
I reverted my change to a Set here: the seen part will only contain up to ctx.depth + 1 elements and in the regular case that is three. Using a Set for such a low amount of elements seems unnecessary, as it increases the code complexity due to having to handle both, an array and a set in case customInspect is set.
I rebased and added a new array fast path. So PTAL Just for fun - this is how the profiling looks like with 0.6 % JavaScript 🤣 |
BridgeAR
commented
Aug 21, 2017
There was a problem hiding this comment.
Not worth it.
- changes
util.inspect.length - drives my IDE crazy
There was a problem hiding this comment.
Well, I do not have a strong opinion.
I went ahead and changed it back to a similar way as before to make you happy ;-)
BridgeAR
commented
Aug 21, 2017
So I pushed a bit more code and updated the benchmarks. The result is pretty decent now. |
BridgeAR
commented
Aug 21, 2017
Ok, the new benchmarks are outdated again as I was able to improve some more things that had significant impact on |
BridgeAR
commented
Aug 24, 2017
So after looking at it again I added some final changes. The benchmarks are updated in the main part. As the code still changed significantly, please take a close look again. @addaleax@refack@andrasq And I have an issue with one test running this locally but I can not explain why the test is failing. I get the following output. @bnoordhuis you wrote that test, would you be so kind and have a look at it? Because I do not see the connection of the error to my changes... |
addaleax
commented
Aug 24, 2017
@BridgeAR That’s a really new test, and I’m pretty sure it’s not related to your PR |
BridgeAR
commented
Aug 24, 2017
@addaleax the weird part is that is it happening only with this PR. On master it does not fail. It is reproducible for me on my local machine and also the CI fails exactly at this test. [EDIT] And the test passes if I call |
BridgeAR
commented
Aug 29, 2017
@bnoordhuis it would be nice if you could have a look at this PR because it somehow breaks this test even though there should not be any connection. The only way for me to fix the test is by calling |
BridgeAR
commented
Sep 5, 2017
@nodejs/collaborators PTAL |
mcollina
left a comment
There was a problem hiding this comment.
LGTM with both CI and CITGM green. Those type of large scale perf improvements can lead to broken production code.
This should be semver-minor at least, and it should bake for LTS for some month before being backported.
In addition use the newer common.expectsError version. PR-URL: nodejs/node#14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
jasnell
commented
Sep 20, 2017
This needs a backport pr to land in v8.x |
PR-URL: #14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
In addition use the newer common.expectsError version. PR-URL: #14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
PR-URL: nodejs#14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
The main optimizations are - Removed visibleKeys - Removed proxy cache - Removed Object.assign - No key concatenating anymore - No key recalculating anymore - Improved indentation logic - Improved string escape logic - Added many fast paths - Optimized code branches a lot - Optimized (boxed) primitive handling - Inline code if possible - Only check extra keys if necessary - Guard against unnecessary more expensive calls This also fixes a bug with special array number keys as e.g. "00". Besides that there were lots of smaller optimizations, the code got a bit cleaned up and a few more tests got in. PR-URL: nodejs#14881Fixes: nodejs#15288 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This fixes a issue brought up in nodejs#15288. PR-URL: nodejs#14881 Refs: nodejs#15288 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Remove unnecessary code parts and outdated code PR-URL: nodejs#14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
PR-URL: #14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
The main optimizations are - Removed visibleKeys - Removed proxy cache - Removed Object.assign - No key concatenating anymore - No key recalculating anymore - Improved indentation logic - Improved string escape logic - Added many fast paths - Optimized code branches a lot - Optimized (boxed) primitive handling - Inline code if possible - Only check extra keys if necessary - Guard against unnecessary more expensive calls This also fixes a bug with special array number keys as e.g. "00". Besides that there were lots of smaller optimizations, the code got a bit cleaned up and a few more tests got in. PR-URL: #14881Fixes: #15288 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Remove unnecessary code parts and outdated code PR-URL: #14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
PR-URL: nodejs/node#14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
PR-URL: nodejs/node#14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
The main optimizations are - Removed visibleKeys - Removed proxy cache - Removed Object.assign - No key concatenating anymore - No key recalculating anymore - Improved indentation logic - Improved string escape logic - Added many fast paths - Optimized code branches a lot - Optimized (boxed) primitive handling - Inline code if possible - Only check extra keys if necessary - Guard against unnecessary more expensive calls This also fixes a bug with special array number keys as e.g. "00". Besides that there were lots of smaller optimizations, the code got a bit cleaned up and a few more tests got in. PR-URL: nodejs/node#14881Fixes: nodejs/node#15288 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This fixes a issue brought up in #15288. PR-URL: nodejs/node#14881 Refs: nodejs/node#15288 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Remove unnecessary code parts and outdated code PR-URL: nodejs/node#14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
In addition use the newer common.expectsError version. PR-URL: nodejs/node#14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MylesBorins
commented
Oct 17, 2017
should this land in LTS? If so it will need to bake a bit longer. Please change labels as appropriate |
I reworked a couple of things in util inspect for performance. The code is fully covered.
EDIT: Updated the comment here and benchmarks.
The main optimizations are
Besides that there were lots of smaller optimizations, the
code got a bit cleaned up and a few more tests got in.
Also two bug fixes came.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
util, benchmark