Skip to content

util: remove style caches from styleText slow path - #63706

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
araujogui:util-styletext-no-cache
Jun 9, 2026
Merged

util: remove style caches from styleText slow path#63706
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
araujogui:util-styletext-no-cache

Conversation

@araujogui

@araujoguiaraujogui commented Jun 1, 2026

Copy link
Copy Markdown
Member

Remove the caches from the slow path since they don't improve performance there. validation dominates the cost, making the lookup savings negligible

util/style-text.js n=1000 validateStream=0 format='#ff0000' messageType='boolean' -0.36 % ±2.99% ±4.02% ±5.32%
util/style-text.js n=1000 validateStream=0 format='#ff0000' messageType='invalid' 0.40 % ±2.49% ±3.34% ±4.39%
util/style-text.js n=1000 validateStream=0 format='#ff0000' messageType='number' ** 2.27 % ±1.68% ±2.24% ±2.91%
util/style-text.js n=1000 validateStream=0 format='#ff0000' messageType='string' 0.82 % ±2.93% ±3.90% ±5.07%
util/style-text.js n=1000 validateStream=0 format='#rotating' messageType='boolean' * 1.25 % ±1.23% ±1.64% ±2.14%
util/style-text.js n=1000 validateStream=0 format='#rotating' messageType='invalid' -0.71 % ±5.57% ±7.50% ±9.94%
util/style-text.js n=1000 validateStream=0 format='#rotating' messageType='number' * 2.59 % ±2.08% ±2.77% ±3.61%
util/style-text.js n=1000 validateStream=0 format='#rotating' messageType='string' -2.07 % ±3.62% ±4.83% ±6.33%
util/style-text.js n=1000 validateStream=0 format='invalid' messageType='boolean' *** 2.36 % ±1.28% ±1.71% ±2.24%
util/style-text.js n=1000 validateStream=0 format='invalid' messageType='invalid' ** 1.57 % ±0.99% ±1.31% ±1.71%
util/style-text.js n=1000 validateStream=0 format='invalid' messageType='number' ** 3.25 % ±2.35% ±3.13% ±4.08%
util/style-text.js n=1000 validateStream=0 format='invalid' messageType='string' 2.07 % ±2.89% ±3.89% ±5.15%
util/style-text.js n=1000 validateStream=0 format='italic' messageType='boolean' * 1.62 % ±1.41% ±1.87% ±2.43%
util/style-text.js n=1000 validateStream=0 format='italic' messageType='invalid' *** 2.00 % ±0.79% ±1.05% ±1.36%
util/style-text.js n=1000 validateStream=0 format='italic' messageType='number' * 3.90 % ±3.08% ±4.15% ±5.50%
util/style-text.js n=1000 validateStream=0 format='italic' messageType='string' -1.52 % ±4.73% ±6.31% ±8.24%
util/style-text.js n=1000 validateStream=0 format='red' messageType='boolean' 1.68 % ±1.93% ±2.56% ±3.33%
util/style-text.js n=1000 validateStream=0 format='red' messageType='invalid' ** 2.29 % ±1.42% ±1.90% ±2.47%
util/style-text.js n=1000 validateStream=0 format='red' messageType='number' ** 2.72 % ±1.93% ±2.57% ±3.34%
util/style-text.js n=1000 validateStream=0 format='red' messageType='string' -0.34 % ±3.61% ±4.82% ±6.30%
util/style-text.js n=1000 validateStream=1 format='#ff0000' messageType='boolean' 0.14 % ±3.35% ±4.51% ±5.96%
util/style-text.js n=1000 validateStream=1 format='#ff0000' messageType='invalid' *** 1.91 % ±0.62% ±0.83% ±1.08%
util/style-text.js n=1000 validateStream=1 format='#ff0000' messageType='number' * 2.08 % ±1.72% ±2.29% ±2.98%
util/style-text.js n=1000 validateStream=1 format='#ff0000' messageType='string' *** 2.24 % ±0.82% ±1.09% ±1.42%
util/style-text.js n=1000 validateStream=1 format='#rotating' messageType='boolean' * 1.73 % ±1.31% ±1.75% ±2.28%
util/style-text.js n=1000 validateStream=1 format='#rotating' messageType='invalid' 0.64 % ±2.20% ±2.95% ±3.88%
util/style-text.js n=1000 validateStream=1 format='#rotating' messageType='number' *** 2.98 % ±1.39% ±1.86% ±2.43%
util/style-text.js n=1000 validateStream=1 format='#rotating' messageType='string' 0.30 % ±2.50% ±3.36% ±4.45%
util/style-text.js n=1000 validateStream=1 format='invalid' messageType='boolean' ** 2.27 % ±1.40% ±1.87% ±2.44%
util/style-text.js n=1000 validateStream=1 format='invalid' messageType='invalid' *** 1.86 % ±0.94% ±1.25% ±1.62%
util/style-text.js n=1000 validateStream=1 format='invalid' messageType='number' ** 3.84 % ±2.81% ±3.75% ±4.91%
util/style-text.js n=1000 validateStream=1 format='invalid' messageType='string' *** 2.26 % ±1.28% ±1.71% ±2.24%
util/style-text.js n=1000 validateStream=1 format='italic' messageType='boolean' *** 2.72 % ±1.51% ±2.02% ±2.64%
util/style-text.js n=1000 validateStream=1 format='italic' messageType='invalid' *** 2.01 % ±0.97% ±1.29% ±1.68%
util/style-text.js n=1000 validateStream=1 format='italic' messageType='number' * 2.19 % ±1.76% ±2.34% ±3.06%
util/style-text.js n=1000 validateStream=1 format='italic' messageType='string' 3.53 % ±3.78% ±5.10% ±6.75%
util/style-text.js n=1000 validateStream=1 format='red' messageType='boolean' 1.32 % ±1.68% ±2.25% ±2.95%
util/style-text.js n=1000 validateStream=1 format='red' messageType='invalid' *** 1.97 % ±1.08% ±1.44% ±1.88%
util/style-text.js n=1000 validateStream=1 format='red' messageType='number' * 2.37 % ±1.80% ±2.40% ±3.13%
util/style-text.js n=1000 validateStream=1 format='red' messageType='string' 2.26 % ±2.31% ±3.09% ±4.07%
Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 40 comparisons, you can thus
expect the following amount of false-positive results:
2.00 false positives, when considering a 5% risk acceptance (*, **, ***),
0.40 false positives, when considering a 1% risk acceptance (**, ***),
0.04 false positives, when considering a 0.1% risk acceptance (***)

CopilotAI review requested due to automatic review settings June 1, 2026 22:01
@nodejs-github-botnodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Jun 1, 2026

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR refactors styleText to reduce reliance on the prebuilt style cache and to build ANSI sequences directly from inspect.colors, while also simplifying the hex-color styling path.

Changes:

  • Lazily initializes the style cache only in the validateStream=false fast path.
  • Replaces cached style lookups with direct reads from inspect.colors and inline ANSI open/close sequence construction.
  • Reworks hex color handling to compute 24-bit ANSI sequences directly instead of using the hex style cache.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadlib/util.js Outdated
Comment threadlib/util.js
Comment threadlib/util.js Outdated
@codecov

codecovBot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.34%. Comparing base (f30139e) to head (6f4298d).
⚠️ Report is 68 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #63706 +/- ##
==========================================
- Coverage 90.35% 90.34% -0.01% 
==========================================
Files 732 732 Lines 236684 236690 +6 Branches 44579 44582 +3 ==========================================
- Hits 213855 213845 -10 - Misses 14544 14557 +13 - Partials 8285 8288 +3 
Files with missing linesCoverage Δ
lib/util.js94.60% <100.00%> (+<0.01%)⬆️

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

@araujogui
araujoguiforce-pushed the util-styletext-no-cache branch from 5dc48c3 to 5980e4fCompareJune 2, 2026 00:06
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
@araujogui
araujoguiforce-pushed the util-styletext-no-cache branch from 5980e4f to 6f4298dCompareJune 2, 2026 00:08
@araujogui

Copy link
Copy Markdown
MemberAuthor

CC @nodejs/performance

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@gurgundaygurgunday left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@mcollinamcollina added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 7, 2026
@nodejs-github-botnodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jun 7, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/63706
✔ Done loading data for nodejs/node/pull/63706
----------------------------------- PR info ------------------------------------
Title util: remove style caches from styleText slow path (#63706)
Author Guilherme Araújo <arauujogui@gmail.com> (@araujogui)
Branch araujogui:util-styletext-no-cache -> nodejs:main
Labels util, needs-ci
Commits 1
- util: remove style caches from styleText slow path
Committers 1
- Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63706
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/63706
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
--------------------------------------------------------------------------------
ℹ This PR was created on Mon, 01 Jun 2026 22:01:24 GMT
✔ Approvals: 2
✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/63706#pullrequestreview-4435453199
✔ - Gürgün Dayıoğlu (@gurgunday): https://github.com/nodejs/node/pull/63706#pullrequestreview-4436132152
✔ Last GitHub CI successful
✘ No Jenkins CI runs detected
--------------------------------------------------------------------------------
✔ Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/27086912762

@H4adH4ad added request-ci Add this label to start a Jenkins CI on a PR. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Jun 8, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 8, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@H4adH4ad added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 9, 2026
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 9, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 4899634 into nodejs:mainJun 9, 2026
81 of 82 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 4899634

aduh95 pushed a commit that referenced this pull request Jun 18, 2026
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: #63706
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
aduh95 pushed a commit that referenced this pull request Jun 25, 2026
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: #63706
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
aduh95 pushed a commit that referenced this pull request Jul 30, 2026
Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
PR-URL: #63706
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ciPRs that need a full CI run.utilIssues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@araujogui@nodejs-github-bot@mcollina@gurgunday@H4ad