Skip to content

util: improve format performance

This simplifies the format() code and significantly improves the performance.

Just a few runs to verify the gain:

                                               confidence improvement accuracy (*)    (**)   (***)
 util/format.js type='many-%' n=600000                ***     18.98 %       ±9.60% ±13.22% ±18.15%
 util/format.js type='no-replace-2' n=600000          ***    396.74 %      ±43.42% ±60.18% ±83.52%
 util/format.js type='no-replace' n=600000            ***    166.64 %      ±32.80% ±44.98% ±61.39%
 util/format.js type='number' n=600000                ***     56.96 %      ±11.00% ±15.14% ±20.80%
 util/format.js type='only-objects' n=600000           **     19.21 %      ±13.09% ±17.82% ±24.05%
 util/format.js type='replace-object' n=600000          *     14.14 %      ±12.46% ±17.04% ±23.16%
 util/format.js type='string-2' n=600000              ***     28.66 %      ±13.20% ±18.21% ±25.07%
 util/format.js type='string' n=600000                ***     59.04 %      ±14.04% ±19.03% ±25.49%
 util/format.js type='unknown' n=600000               ***    338.50 %      ±37.78% ±52.19% ±72.06%

CI https://ci.nodejs.org/job/node-test-pull-request/19442/

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading