Skip to content

net: skip IPv6 regex when the string has no colon - #66165

Open
anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cursor/net-hotpath-ead2
Open

anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cursor/net-hotpath-ead2

Conversation

@anonrig

@anonrig anonrig commented Sep 21, 2026

Copy link
Copy Markdown
Member

net.isIPv6() always ran the large IPv6 regular expression, including for IPv4 addresses and hostnames. An IPv6 address always contains :, so reject those strings first.

Object / toString inputs still go through RegExp.prototype.test so existing coercion (covered by test-net-isip.js) is unchanged.

This change was implemented with assistance from a closed-source coding agent. I verified the source, official benchmark/net results, and test-net-isip.js / test-net-blocklist.js.

Official benches

Three-run medians, n=1e7:

bench main this PR delta
net/net-is-ip-v6.js 6.48M 8.23M +27%
net/net-is-ip-v4.js 12.31M 12.52M unchanged

Tests

test-net-isip.js, test-net-blocklist.js.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. net Issues and PRs related to the net subsystem. labels Sep 21, 2026
@anonrig
anonrig marked this pull request as ready for review September 21, 2026 04:07
IPv6 addresses always contain ':'. Reject IPv4 addresses and
hostnames before running the IPv6 regular expression.

Official benchmark/net/net-is-ip-v6.js is about 27% faster.
net-is-ip-v4.js is unchanged.

Assisted-by: a closed-source coding agent
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/net-hotpath-ead2 branch from b4aacd6 to da12549 Compare September 21, 2026 04:32
@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.29%. Comparing base (dd5dfb5) to head (da12549).
⚠️ Report is 37 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66165      +/-   ##
==========================================
+ Coverage   90.27%   90.29%   +0.02%     
==========================================
  Files         790      790              
  Lines      271651   272049     +398     
  Branches    51842    51939      +97     
==========================================
+ Hits       245228   245658     +430     
+ Misses      16928    16889      -39     
- Partials     9495     9502       +7     
Files with missing lines Coverage Δ
lib/internal/net.js 100.00% <100.00%> (ø)

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

@pimterry pimterry added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark GHA (net): https://github.com/nodejs/node/actions/runs/35579915982

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 21, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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. net Issues and PRs related to the net subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants