node
node copied to clipboard
http,net: optimize repeated property access
Summary
- Cache frequently accessed object properties in local variables to reduce property lookup overhead
- Optimizes HTTP Agent constructor and net.Socket configuration methods
Details
This PR optimizes repeated property access patterns in network-related modules:
HTTP Agent Constructor (lib/_http_agent.js)
- Caches
this.optionsin a localoptsvariable - Eliminates 14+ repeated property access chains during Agent instantiation
- HTTP Agents are created frequently for HTTP/HTTPS requests
Socket Configuration Methods (lib/net.js)
setNoDelay(): Cachesthis._handleto avoid 2 property lookupssetKeepAlive(): Cachesthis._handleto avoid 2 property lookups- These methods are called during socket setup for every TCP connection
Performance Impact
- Reduces object traversal overhead in hot paths
- Particularly beneficial for applications with high connection volumes
- Follows the same optimization pattern as recent PRs (#59934, #59967)
Test plan
- [x] Existing HTTP/HTTPS tests pass
- [x] Existing net tests pass
- [x] No functional changes, only performance optimizations
- [x] Manually verified Agent creation and socket configuration work correctly
Review requested:
- [ ] @nodejs/http
- [ ] @nodejs/net
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 88.44%. Comparing base (55cd2e5) to head (ca579ec).
:warning: Report is 573 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #59968 +/- ##
==========================================
+ Coverage 88.41% 88.44% +0.02%
==========================================
Files 703 703
Lines 207421 207426 +5
Branches 39993 40012 +19
==========================================
+ Hits 183398 183448 +50
+ Misses 15996 15945 -51
- Partials 8027 8033 +6
| Files with missing lines | Coverage Δ | |
|---|---|---|
| lib/_http_agent.js | 97.33% <100.00%> (+0.01%) |
:arrow_up: |
| lib/net.js | 95.28% <100.00%> (+<0.01%) |
:arrow_up: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
CI: https://ci.nodejs.org/job/node-test-pull-request/69565/
CI: https://ci.nodejs.org/job/node-test-pull-request/69567/
CI: https://ci.nodejs.org/job/node-test-pull-request/70391/