Skip to content

Conversation

@RafaelGSS
Copy link
Member

This commit optimizes the util.styleText when validateStream is false


➜  node2 git:(27ec4315b1f) ✗ node benchmark/compare.js --old ./node --new ./node-optimize --filter style-text util > style-text.out
[00:00:30|% 100| 1/1 files | 60/60 runs | 24/24 configs]: Done
 %
➜  node2 git:(27ec4315b1f) ✗ node-benchmark-compare style-text.out
                                                                                  confidence improvement accuracy (*)     (**)    (***)
util/style-text.js n=1000 validateStream=0 format='invalid' messageType='boolean'                 3.10 %       ±9.95%  ±13.24%  ±17.23%
util/style-text.js n=1000 validateStream=0 format='invalid' messageType='invalid'                -8.84 %      ±10.73%  ±14.29%  ±18.61%
util/style-text.js n=1000 validateStream=0 format='invalid' messageType='number'                 -8.78 %       ±9.00%  ±12.00%  ±15.67%
util/style-text.js n=1000 validateStream=0 format='invalid' messageType='string'                 -9.09 %       ±9.55%  ±12.71%  ±16.55%
util/style-text.js n=1000 validateStream=0 format='italic' messageType='boolean'                 -4.34 %      ±10.50%  ±13.98%  ±18.20%
util/style-text.js n=1000 validateStream=0 format='italic' messageType='invalid'                 -0.16 %      ±11.98%  ±15.95%  ±20.75%
util/style-text.js n=1000 validateStream=0 format='italic' messageType='number'                  -4.44 %      ±10.75%  ±14.31%  ±18.62%
util/style-text.js n=1000 validateStream=0 format='italic' messageType='string'          ***    572.71 %     ±129.86% ±174.99% ±232.29%
util/style-text.js n=1000 validateStream=0 format='red' messageType='boolean'                     4.81 %      ±11.07%  ±14.73%  ±19.17%
util/style-text.js n=1000 validateStream=0 format='red' messageType='invalid'              *     12.15 %      ±10.44%  ±13.91%  ±18.14%
util/style-text.js n=1000 validateStream=0 format='red' messageType='number'                      4.98 %       ±8.31%  ±11.07%  ±14.44%
util/style-text.js n=1000 validateStream=0 format='red' messageType='string'             ***    602.97 %     ±124.23% ±167.42% ±222.24%
util/style-text.js n=1000 validateStream=1 format='invalid' messageType='boolean'                 1.49 %       ±5.91%   ±7.87%  ±10.24%
util/style-text.js n=1000 validateStream=1 format='invalid' messageType='invalid'                -9.42 %       ±9.62%  ±12.82%  ±16.73%
util/style-text.js n=1000 validateStream=1 format='invalid' messageType='number'                 -4.64 %       ±9.81%  ±13.06%  ±17.02%
util/style-text.js n=1000 validateStream=1 format='invalid' messageType='string'                  9.27 %      ±10.24%  ±13.65%  ±17.83%
util/style-text.js n=1000 validateStream=1 format='italic' messageType='boolean'                  6.04 %       ±9.99%  ±13.30%  ±17.34%
util/style-text.js n=1000 validateStream=1 format='italic' messageType='invalid'                 -3.24 %       ±9.79%  ±13.04%  ±16.98%
util/style-text.js n=1000 validateStream=1 format='italic' messageType='number'                  -1.61 %       ±9.45%  ±12.58%  ±16.38%
util/style-text.js n=1000 validateStream=1 format='italic' messageType='string'                   2.10 %       ±9.03%  ±12.05%  ±15.74%
util/style-text.js n=1000 validateStream=1 format='red' messageType='boolean'                    -0.12 %       ±9.65%  ±12.84%  ±16.71%
util/style-text.js n=1000 validateStream=1 format='red' messageType='invalid'                    -5.44 %      ±11.00%  ±14.64%  ±19.07%
util/style-text.js n=1000 validateStream=1 format='red' messageType='number'                     -1.35 %       ±8.12%  ±10.81%  ±14.08%
util/style-text.js n=1000 validateStream=1 format='red' messageType='string'               *     -7.68 %       ±7.03%   ±9.36%  ±12.20%

Be aware that when doing many comparisons the risk of a false-positive result increases.
In this case, there are 24 comparisons, you can thus expect the following amount of false-positive results:
  1.20 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.24 false positives, when considering a   1% risk acceptance (**, ***),
  0.02 false positives, when considering a 0.1% risk acceptance (***)

We are investigating how we can further optimise it without changing the API drastically.

This commit optimizes the util.styleText when validateStream
is false

Co-Authored-By: Bruno Rodrigues <[email protected]>
Signed-off-by: RafaelGSS <[email protected]>
@RafaelGSS RafaelGSS added the performance Issues and PRs related to the performance of Node.js. label Feb 12, 2026
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Feb 12, 2026
@RafaelGSS
Copy link
Member Author

RafaelGSS commented Feb 12, 2026

@BridgeAR In our understanding to further optimize this, we would need to encapsulate this API into a Colorize-like API, where we could call .red().bold(). IIRC You have opened a PR to add a similar functionality, but it never landed on main.

Any objections to us pursuing that idea in a separate PR?

@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

❌ Patch coverage is 75.29412% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.73%. Comparing base (4a13a62) to head (5f9c663).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
lib/util.js 75.29% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61792      +/-   ##
==========================================
- Coverage   89.76%   89.73%   -0.03%     
==========================================
  Files         675      675              
  Lines      204674   204689      +15     
  Branches    39330    39311      -19     
==========================================
- Hits       183716   183675      -41     
- Misses      13235    13300      +65     
+ Partials     7723     7714       -9     
Files with missing lines Coverage Δ
lib/util.js 94.10% <75.29%> (-3.88%) ⬇️

... and 36 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants