Skip to content
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

lib: limit split function calls to prevent excessive array length #57501

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

Conversation

gurgunday
Copy link
Contributor

Speeds up split calls by returning early when we reach the desired length

Some of these split calls are used for string replacement, I'll do another pass converting those to StringPrototypeReplaceAll afterward

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Mar 16, 2025
Copy link

codecov bot commented Mar 16, 2025

Codecov Report

Attention: Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.23%. Comparing base (8a5a849) to head (4aa870e).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/test_runner/utils.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #57501   +/-   ##
=======================================
  Coverage   90.22%   90.23%           
=======================================
  Files         629      629           
  Lines      184847   184846    -1     
  Branches    36207    36205    -2     
=======================================
+ Hits       166780   166797   +17     
- Misses      11015    11019    +4     
+ Partials     7052     7030   -22     
Files with missing lines Coverage Δ
lib/internal/blob.js 99.80% <100.00%> (ø)
lib/internal/debugger/inspect.js 93.98% <100.00%> (ø)
lib/internal/errors.js 97.47% <100.00%> (ø)
lib/internal/modules/cjs/loader.js 98.26% <100.00%> (ø)
lib/internal/modules/esm/module_job.js 98.27% <100.00%> (ø)
lib/internal/repl/await.js 98.09% <100.00%> (ø)
lib/internal/tty.js 97.04% <100.00%> (ø)
lib/internal/util/debuglog.js 95.21% <100.00%> (+<0.01%) ⬆️
lib/internal/worker/js_transferable.js 98.55% <100.00%> (ø)
lib/tls.js 95.93% <100.00%> (ø)
... and 1 more

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

@@ -360,7 +360,7 @@ function resolveObjectURL(url) {
try {
const parsed = new URL(url);

const split = StringPrototypeSplit(parsed.pathname, ':');
const split = StringPrototypeSplit(parsed.pathname, ':', 3);
Copy link
Member

Choose a reason for hiding this comment

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

If we want to improve the performance, we should actually do the splitting manually by checking with indexOf and slicing out the variables we need. The same applies to multiple other places here.

This particular case will only improve the performance in case the pathname is rather untypical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going to do that in another pass, same for replacements where we can just use replaceAll

Can I do that or would you like to combine them all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And btw current behavior rejects if more than 1 occurrence of : is found, so using split here kinda makes sense to get that number before continuing further

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants