Skip to content

util: improve util.format performance

By manually copying arguments and breaking the try/catch out, we are able to improve the performance of util.format by 20-100% (depending on the types).

Also includes a util.format benchmark.

The numbers:

running ./node
util/format.js
running ./node_before
util/format.js

util/format.js n=1000000 type=string: ./node: 7866600 ./node_before: 1705900 ... 361.13%
util/format.js n=1000000 type=number: ./node: 7718000 ./node_before: 1778900 ... 333.87%
util/format.js n=1000000 type=object: ./node: 1811800 ./node_before: 800160 .... 126.43%
util/format.js n=1000000 type=unknown: ./node: 13045000 ./node_before: 2650300 . 392.22%
util/format.js n=1000000 type=no-replace: ./node: 1541500 ./node_before: 956760 . 61.11%

EDIT: I updated the numbers after rebasing on master and with @mscdex's changes included as well.

Merge request reports

Loading