Skip to content

Conversation

@mertcanaltin
Copy link
Member

@mertcanaltin mertcanaltin commented Jan 13, 2026

fix: // TODO(bnoordhuis) Use slab allocation, O(n) allocs is bad.

before:

http/bench-parser-fragmented.js n=100000 len=8 frags=2: 951,629.0928924936
http/bench-parser-fragmented.js n=100000 len=16 frags=2: 677,295.1203426437
http/bench-parser-fragmented.js n=100000 len=8 frags=4: 759,881.7857984888
http/bench-parser-fragmented.js n=100000 len=16 frags=4: 509,278.74034996366
http/bench-parser-fragmented.js n=100000 len=8 frags=8: 680,706.0381048893
http/bench-parser-fragmented.js n=100000 len=16 frags=8: 466,898.1840452692

after:
52% faster HTTP header parsing

http/bench-parser-fragmented.js n=100000 len=8 frags=2: 1,231,534.676937666
http/bench-parser-fragmented.js n=100000 len=16 frags=2: 890,580.6675901335
http/bench-parser-fragmented.js n=100000 len=8 frags=4: 1,117,723.8010822271
http/bench-parser-fragmented.js n=100000 len=16 frags=4: 789,398.1180369954
http/bench-parser-fragmented.js n=100000 len=8 frags=8: 869,642.0937523921
http/bench-parser-fragmented.js n=100000 len=16 frags=8: 711,293.8345939534

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. http_parser Issues and PRs related to the HTTP Parser dependency or the http_parser binding. needs-ci PRs that need a full CI run. labels Jan 13, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements slab allocation for HTTP header parsing to optimize performance by reducing heap allocations. The implementation addresses a TODO comment about O(n) allocations being inefficient and achieves a reported 52% performance improvement in HTTP header parsing benchmarks.

Changes:

  • Added a 128-byte fixed-size buffer (slab) to each StringPtr instance for caching small strings
  • Modified Save() and Update() methods to use slab allocation before falling back to heap allocation
  • Added using_slab_ flag to track slab usage state alongside existing on_heap_ flag

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

@codecov
Copy link

codecov bot commented Jan 13, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.52%. Comparing base (daeafc0) to head (9115556).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/node_http_parser.cc 90.90% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #61375   +/-   ##
=======================================
  Coverage   88.51%   88.52%           
=======================================
  Files         704      704           
  Lines      208776   208790   +14     
  Branches    40301    40301           
=======================================
+ Hits       184803   184832   +29     
+ Misses      15966    15925   -41     
- Partials     8007     8033   +26     
Files with missing lines Coverage Δ
src/node_http_parser.cc 84.94% <90.90%> (+0.14%) ⬆️

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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


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

Reset();
}

// Memory impact: ~8KB per parser (66 StringPtr × 128 bytes).
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The memory calculation is slightly inaccurate. 66 × 128 = 8,448 bytes, which is approximately 8.25KB, not 8KB. Consider updating to '~8.4KB' or '~8.5KB' for better accuracy.

Suggested change
// Memory impact: ~8KB per parser (66 StringPtr × 128 bytes).
// Memory impact: ~8.4KB per parser (66 StringPtr × 128 bytes).

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

Thank you overly pedantic AI code review. The ~8KB is accurate enough here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. http_parser Issues and PRs related to the HTTP Parser dependency or the http_parser binding. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants