-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
util: change inspect depth #22846
util: change inspect depth #22846
Conversation
\cc @iarna since this has impacted |
doc/api/util.md
Outdated
@@ -360,6 +364,9 @@ stream.write('With ES6'); | |||
<!-- YAML | |||
added: v0.3.0 | |||
changes: | |||
- version: REPLACEME | |||
pr-url: https://github.com/nodejs/node/pull/REPLACEME | |||
description: The `depth` default changed to 20. |
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.
20
-> `20`
?
Is this semver-major? |
@BridgeAR @vsemozhetbyt https://nodejs.org/api/util.html#util_util_inspect_object_options says
As such, I don't think this needs to be semver-major |
@AyushG3112 in most cases I'd agree but changing a default option does seem to be a semver-major change for me. |
Change is always disruptive, what I'm not seeing here (and forgive if I'm just missing it) is any discussion of what the benefit of this change is? And how does it balance with the potential disruption? Has anyone involved with this change done any investigation into potential impact? |
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.
CI: https://ci.nodejs.org/job/node-test-pull-request/17212/
CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1546/
@iarna From previous conversation with @BridgeAR, I think the benefit he’s seeing here is that the output is more verbose, and depth: 2
misses too much useful information.
Personally, I agree with that part of the assessment, but would prefer a depth of 4
or so that is much less dramatic and doesn’t lead to overwhelmingly large output.
doc/api/util.md
Outdated
@@ -183,6 +183,10 @@ property take precedence over `--trace-deprecation` and | |||
<!-- YAML | |||
added: v0.5.3 | |||
changes: | |||
- version: REPLACEME | |||
pr-url: https://github.com/nodejs/node/pull/17907 | |||
description: The `%o` specifiers `depth` option will now fall back to the |
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.
Is this a typo (specifier’s
)?
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.
I guess so. @vsemozhetbyt @Trott can you verify this? :-)
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.
I am not a native speaker, but it seems for me that `%o` specifier's `depth` option
or `%o` specifier `depth` option
would be OK?
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.
Yes, there should be an apostrophe: specifier's
@iarna I spoke to multiple people before originally wanting to change this default. The @addaleax setting the limit to |
1b3e54d
to
6379db9
Compare
@nodejs/util PTAL |
I personally like this change a lot, 👍 |
@nodejs/tsc PTAL |
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.
LGTM
Heads up the error helpers use Lines 654 to 660 in a7b59d6
|
@jdalton it would indeed change this but to me it seems to the better, not to the worse. I would prefer to keep it this way or go ahead and explicitly add option to inspect it further. |
6379db9
to
702cf21
Compare
Rebased due to conflicts. |
It might really just be me, but even that seems excessive for inspecting an object to get an overview over it? That’s still 4 full-screen terminal pages on my machine. Maybe the point is that |
The reason for the size of these objects is mainly redundant information that I am about to limit with a couple of PRs that I opened yesterday. Especially, We also have lots of symbols on our objects that are only meant for Node core and those are visible to all users. Hiding those is also going to reduce the output to a more regular size. I also want to keep the "overview" functionality in the In an server application I personally want to have the full data logged, no matter how big it is. Otherwise I might loose information that is important to me. So my suggestion is: we clean up all Node core internal properties to be only visible when using |
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.
Changed my mind, I think this is a better approach than #23062. The http example shows that logged lines do not grow in size considerable with increasing depth, so I guess we should be save, even with a depth of 20.
Agree, but please retain plain underscore-prefixed properties, if possible. While discouraged, I often find them useful to look at while debugging. |
Right, but not all Node.js applications are server applications… I still think this PR is not a good idea, but I don’t want to be the only one blocking this. If everybody else is okay with it, we can try to go for it in Node 11 and see how things turn out. |
@addaleax I would rather have consensus before landing. What could be changed / done so you would not think it's the wrong thing to do? |
Resumbed build https://ci.nodejs.org/job/node-test-commit/21855/ ✔️ |
Those are a different thing when compared to the symbol properties in general. So at least I personally would not touch them in most cases. |
Ping @addaleax is there anything that I could change so you feel more comfortable with this PR? |
@BridgeAR I don’t think so … I still think it’s not a good idea, and I guess we’ll just have to see how this plays out in the real world. |
The current default is not ideal in most use cases. Therefore it is changed to inspect objects to a maximum depth of 20 in case util.inspect is called with it's defaults. The default is kept at 2 when using console.log() and similar in the repl. PR-URL: nodejs#17907 Refs: nodejs#12693 PR-URL: nodejs#22846 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
Since the default for depth is changed to `20` it is logical to change the %o default as well. It will now always use the default depth. PR-URL: nodejs#17907 Refs: nodejs#12693 PR-URL: nodejs#22846 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
Probably due to some PR/PR interaction this fails on master: Revert PR #23231 |
@BridgeAR I think this needs to be reverted. It makes the default behaviour pretty much unusable. Logging an object that used to be instant now takes ~66 seconds, and creates 1,793,699 lines of output. |
I am trying to come up with different kinds of objects that might cause such an extreme behavior but I can't. It would be great to know the shape of the object, the reason why it is so enormous (most data structures are significantly smaller) and what system you used. My guess is that logging the object almost hits the maximum heap size and the stop logging heuristic is not triggered. But even that is difficult to tell without further information. |
@BridgeAR logging an instance of this https://github.com/devsnek/engine262/blob/1b1631d9f0e8f24fd3b7af16a823acace1c25ca7/src/value.mjs#L218 i'm on macos, and here's the output http://s.gc.gy/2018-10-05-12314.out |
I had another look into this and the main issue is the actual output size, not the inspection time. Inspection itself is pretty fast but logging more than 128 MB is slow. Piping improves the performance but it's still slow. So I suggest the following for Node.js 11: I open a PR to change the default depth to 5 instead of 20 and afterwards I work on a PR to change the inspection algorithm from inspecting the most inner depth first to fully inspecting the most outer depth first before moving on to the next level. After each level the current object size is measured and if it exceeds a specific limit, the inner levels will not be fully inspected anymore. I also open another PR to add a new option to @addaleax @devsnek @silverwind what do you think? |
whatever keeps it fast and reasonable is fine with me. even if the above output happened instantly I obviously wouldn't want it in my console. |
@BridgeAR Yes, I think that sounds okay to me. |
I'd wager most of that is terminal rendering time, but good to know that such big objects are not as uncommon as we thought.
That sounds pretty complicated and not easy to understand/document. I'd say keep it at a simple number, 4 or 5, I don't really care. |
@BridgeAR I haven't thought about the traversing algorithm much, but looks like the proposal is to traverse the object breadth wise instead of depth wise, to find the size at the each level. Can we find circular references if we did breadth wise traversal? |
Circular reference detection will stay the same. It is not completely trivial to do a breath wise inspection because we have to delay object inspection and have to iterate over all properties once more. So the only concern for me is performance and implementation complexity. |
The current default is not ideal in most use cases. Therefore it is
changed to inspect objects to a maximum depth of 20 in case
util.inspect is called with it's defaults. The default is kept at 2
when using console.log() and similar in the repl.
See the commit message for further details.
This should not be an issue for e.g., npm, since the maximum output
size is limited to 128 MB of data.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes