Skip to content

Commit 742b304

Browse files
jasnelltargos
authored andcommitted
doc: warn about using util.inspect/util.format
Because of the potential performance bottlenecks that may be introduced by `util.inspect()` and `util.format()` in production hot path code. Based on real user feedback, it is not obvious that these are intended to be debugging tools. PR-URL: #17791 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 5f1a01d commit 742b304

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

doc/api/util.md

+10
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ without any formatting.
225225
util.format('%% %s'); // '%% %s'
226226
```
227227

228+
Please note that `util.format()` is a synchronous method that is mainly
229+
intended as a debugging tool. Some input values can have a significant
230+
performance overhead that can block the event loop. Use this function
231+
with care and never in a hot code path.
232+
228233
## util.getSystemErrorName(err)
229234
<!-- YAML
230235
added: v9.7.0
@@ -437,6 +442,11 @@ console.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 }));
437442
// chunks.
438443
```
439444

445+
Please note that `util.inspect()` is a synchronous method that is mainly
446+
intended as a debugging tool. Some input values can have a significant
447+
performance overhead that can block the event loop. Use this function
448+
with care and never in a hot code path.
449+
440450
### Customizing `util.inspect` colors
441451

442452
<!-- type=misc -->

0 commit comments

Comments
 (0)