Skip to content

util(styleText): optimise + benchmark #58063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

AugustinMauroy
Copy link
Member

@AugustinMauroy AugustinMauroy commented Apr 28, 2025

I had modify logic behind. using a reducer, it's should be quicker. And I had updated benchmark

Plus I had updated test to use node:test in goal of having better DX when something fails.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/performance

@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 Apr 28, 2025
Copy link

codecov bot commented Apr 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.21%. Comparing base (6cd1c09) to head (a9d13f2).
Report is 16 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #58063   +/-   ##
=======================================
  Coverage   90.21%   90.21%           
=======================================
  Files         630      630           
  Lines      186391   186448   +57     
  Branches    36610    36620   +10     
=======================================
+ Hits       168146   168209   +63     
+ Misses      11066    11038   -28     
- Partials     7179     7201   +22     
Files with missing lines Coverage Δ
lib/util.js 97.77% <100.00%> (+0.01%) ⬆️

... and 34 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.

@lpinca
Copy link
Member

lpinca commented Apr 28, 2025

Plus I had updated test to use node:test in goal of having better DX when something fails.

Please don't do that, we discussed it a lot. Those refactors are not useful.

@AugustinMauroy
Copy link
Member Author

Please don't do that, we discussed it a lot. Those refactors are not useful.

oh okay, surprising because the use cases with the it allow you to find your way around the test and, in the event of a failure, search the codebase.
Do you have a link to the discussion?

@lpinca
Copy link
Member

lpinca commented Apr 28, 2025

Start here #54796 and here #56027, follow the links there.

@AugustinMauroy AugustinMauroy force-pushed the pref(util)-optimise-styleText branch 2 times, most recently from 7e02fbd to 369b13f Compare April 29, 2025 09:34
@AugustinMauroy AugustinMauroy force-pushed the pref(util)-optimise-styleText branch from cf38ccd to ae69a04 Compare April 29, 2025 09:47
lib/util.js Outdated
@@ -129,8 +128,9 @@ function styleText(format, text, { validateStream = true, stream = process.stdou
throw new ERR_INVALID_ARG_TYPE('stream', ['ReadableStream', 'WritableStream', 'Stream'], stream);
}

// If the stream is falsy or should not be colorized, set skipColorize to true
skipColorize = !lazyUtilColors().shouldColorize(stream);
if (!lazyUtilColors().shouldColorize(stream)) {
Copy link
Member

@marco-ippolito marco-ippolito Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

early return will skip validation so its a necessary overhead
#56722 (comment)

Copy link
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Marco mentioned, the "overhead" is necessary.

@AugustinMauroy
Copy link
Member Author

Can I just keep benchmark change ?

@RafaelGSS
Copy link
Member

Can I just keep benchmark change ?

Yes, but I'd do it as a separate benchmark, so we don't need to have benchmarks for:

noColors: true, format: 'italic',
noColors: true, format: 'underline',
noColors: true, format: 'read',

As they will all be the same. So, adding it as a separate benchmark makes more sense.

@AugustinMauroy AugustinMauroy force-pushed the pref(util)-optimise-styleText branch from 029701a to ef34ff0 Compare April 30, 2025 10:14
@AugustinMauroy AugustinMauroy changed the title perf(util): optimise styleText util(styleText): optimise + benchmark Apr 30, 2025
validateStream: [1, 0],
n: [1e3],
});
withColor: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, create a different file instead. style-text-nocolor.js

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh okay got it !

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. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants