diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-16 18:10:08 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-09-13 10:49:04 +0200 |
commit | eb61127c48ba59e52d7cea293ad80fa54000939c (patch) | |
tree | bac34ae84a86c310684a0148a42b6a8d71047759 /doc | |
parent | 1cee08536794b6d7bc8d3b9ace2b494c74985f7d (diff) | |
download | android-node-v8-eb61127c48ba59e52d7cea293ad80fa54000939c.tar.gz android-node-v8-eb61127c48ba59e52d7cea293ad80fa54000939c.tar.bz2 android-node-v8-eb61127c48ba59e52d7cea293ad80fa54000939c.zip |
util: limit inspection output size to 128 MB
The maximum hard limit that `util.inspect()` could theoretically handle
is the maximum string size. That is ~2 ** 28 on 32 bit systems and
~2 ** 30 on 64 bit systems.
Due to the recursive algorithm a complex object could easily exceed
that limit without throwing an error right away and therefore
crashing the application by exceeding the heap limit.
`util.inspect()` is fast enough to compute 128 MB of data below one
second on an Intel(R) Core(TM) i7-5600U CPU. This hard limit allows
to inspect arbitrary big objects from now on without crashing the
application or blocking the event loop significantly.
PR-URL: https://github.com/nodejs/node/pull/22756
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/util.md | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/doc/api/util.md b/doc/api/util.md index 44495e977d..d67f46c043 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -360,6 +360,10 @@ stream.write('With ES6'); <!-- YAML added: v0.3.0 changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/22756 + description: The inspection output is now limited to about 128 MB. Data + above that size will not be fully inspected. - version: v10.6.0 pr-url: https://github.com/nodejs/node/pull/20725 description: Inspecting linked lists and similar objects is now possible @@ -408,11 +412,11 @@ changes: TODO(BridgeAR): Deprecate `maxArrayLength` and replace it with `maxEntries`. --> - * `maxArrayLength` {number} Specifies the maximum number of `Array`, + * `maxArrayLength` {integer} Specifies the maximum number of `Array`, [`TypedArray`][], [`WeakMap`][] and [`WeakSet`][] elements to include when formatting. Set to `null` or `Infinity` to show all elements. Set to `0` or negative to show no elements. **Default:** `100`. - * `breakLength` {number} The length at which an object's keys are split + * `breakLength` {integer} The length at which an object's keys are split across multiple lines. Set to `Infinity` to format an object as a single line. **Default:** `60` for legacy compatibility. * `compact` {boolean} Setting this to `false` changes the default indentation @@ -532,9 +536,10 @@ console.log(inspect(weakSet, { showHidden: true })); ``` Please note that `util.inspect()` is a synchronous method that is mainly -intended as a debugging tool. Some input values can have a significant -performance overhead that can block the event loop. Use this function -with care and never in a hot code path. +intended as a debugging tool. Its maximum output length is limited to +approximately 128 MB and input values that result in output bigger than that +will not be inspected fully. Such values can have a significant performance +overhead that can block the event loop for a significant amount of time. ### Customizing `util.inspect` colors |