Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uputil: change inspect depth default #17907
Conversation
nodejs-github-bot
added
console
repl
util
labels
Dec 28, 2017
BridgeAR
added
the
semver-major
label
Dec 28, 2017
lpinca
reviewed
Dec 29, 2017
| @@ -317,7 +317,9 @@ Object.defineProperty(inspect, 'defaultOptions', { | |||
| if (options === null || typeof options !== 'object') { | |||
| throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object'); | |||
| } | |||
| Object.assign(inspectDefaultOptions, options); | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
TimothyGu
Dec 30, 2017
Member
- Do we actually care about the performance of inspection? I thought we didn’t.
- Same concern here as @lpinca. This is quite literally reinventing the wheel, and type checks for object are quite fast in modern V8.
This comment has been minimized.
This comment has been minimized.
BridgeAR
Jan 2, 2018
Author
Member
Updated the use _extend as it will still be faster than Object.assign
This comment has been minimized.
This comment has been minimized.
BridgeAR
Jan 2, 2018
Author
Member
About the performance - just recently I heard that inspect came up in a flamegraph. Seems like people use it a lot. I am aware that setting the default options will not be a big thing but the first implementation (not changing inspect for console.*) used it a lot and that is why I decided to optimize it as well.
This comment has been minimized.
This comment has been minimized.
|
Not sure I like the complexity introduced here. Given that this is already flagged as |
This comment has been minimized.
This comment has been minimized.
|
@silverwind I do not see a big difference between 5 and unlimited. Most entries are not that deeply nested and if they are, you likely want to see everything. To prevent huge diffs, the max array entries option is way more efficient as this would otherwise be more difficult to handle. About the complexity: I am fine with showing everything as a new default for console.* and this would remove the complexity again. But it would be a more significant change and I tried to minimize the breaking change. For the repl it might be best to stay with the current default though. The reason is that some modules like |
jasnell
approved these changes
Dec 29, 2017
This comment has been minimized.
This comment has been minimized.
|
@jasnell what do you think about removing the limit for |
This comment has been minimized.
This comment has been minimized.
|
Changing the default for |
BridgeAR
added some commits
Dec 30, 2017
BridgeAR
force-pushed the
BridgeAR:change-inspect-defaults
branch
from
2bb38d6
to
2721767
Dec 30, 2017
This comment has been minimized.
This comment has been minimized.
|
I changed the code to default to unlimited for the console functions as well. CITGM https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1179/ |
TimothyGu
reviewed
Dec 30, 2017
| @@ -73,4 +74,8 @@ module.exports = class BufferList { | |||
| } | |||
| return ret; | |||
| } | |||
|
|
|||
| [customInspectSymbol]() { | |||
| return `${this.constructor.name} { length: ${this.length} }`; | |||
This comment has been minimized.
This comment has been minimized.
TimothyGu
Dec 30, 2017
Member
You could return { __proto__: Object.getPrototypeOf(this), length: this.length } which would also give coloring etc. for free.
This comment has been minimized.
This comment has been minimized.
BridgeAR
Jan 2, 2018
Author
Member
Using __proto__ will actually result in a `call stack size exceeded error. I decided to call inspect directly instead to highlight the color in case it is needed.
| @@ -317,7 +317,9 @@ Object.defineProperty(inspect, 'defaultOptions', { | |||
| if (options === null || typeof options !== 'object') { | |||
| throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'options', 'Object'); | |||
| } | |||
| Object.assign(inspectDefaultOptions, options); | |||
This comment has been minimized.
This comment has been minimized.
TimothyGu
Dec 30, 2017
Member
- Do we actually care about the performance of inspection? I thought we didn’t.
- Same concern here as @lpinca. This is quite literally reinventing the wheel, and type checks for object are quite fast in modern V8.
starkwang
referenced this pull request
Dec 30, 2017
Closed
Some jenkins jobs failed to push state. #163
This comment has been minimized.
This comment has been minimized.
BridgeAR
added
author ready
and removed
author ready
labels
Jan 2, 2018
BridgeAR
requested a review
from nodejs/tsc
Jan 2, 2018
targos
requested changes
Jan 2, 2018
|
Can you please change the documentation of |
addaleax
reviewed
Jan 2, 2018
| @@ -73,4 +75,9 @@ module.exports = class BufferList { | |||
| } | |||
| return ret; | |||
| } | |||
|
|
|||
| [customInspectSymbol]() { | |||
This comment has been minimized.
This comment has been minimized.
addaleax
Jan 2, 2018
Member
I’d just use util.inspect.custom here, it saves people looking at this code one round-trip to another file
This comment has been minimized.
This comment has been minimized.
BridgeAR
added some commits
Jan 3, 2018
This comment has been minimized.
This comment has been minimized.
|
I updated the documentation and added the history entry. I also changed the |
targos
approved these changes
Jan 7, 2018
| * `depth` {number} Specifies the number visible nested Objects in an `object`. | ||
| This is useful to minimize the inspection output for large complicated | ||
| objects. To make it recurse indefinitely pass `null` or `Infinity`. Defaults | ||
| to `null`. |
BridgeAR commentedDec 28, 2017
Right now the defaults for
util.inspectare often not ideal. This is a first step to improve those. I tried not to break to much and keep the current behavior for thereplandconsole.Refs: #12693
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
util, console