Repository navigation
Conversation
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67232 +/- ##
==========================================
+ Coverage 90.71% 90.73% +0.01%
==========================================
Files 801 801
Lines 280906 280964 +58
Branches 54249 54269 +20
==========================================
+ Hits 254832 254940 +108
+ Misses 16246 16200 -46
+ Partials 9828 9824 -4
🚀 New features to boost your workflow:
|
7e0458a to
4b4d19e
Compare
Ethan-Arrowood
left a comment
There was a problem hiding this comment.
Mainly want to see what the benchmarks actually look like for this change. Need to fix that error stack frames thing too. Otherwise, I'm definitely in support of a change like this to make the main headers validation path faster.
|
https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1907/ benchmark/http/set-header-rest.js |
4b4d19e to
8c04114
Compare
|
Looks like my own #67528 caused a merge conflict here. Sorry about that. Can you rebase and rerun the benchmarks? What I'm seeing so far looks good though so I'm optimistic we can land this asap! |
Cache each valid header name with its lowercased form and the last valid string value set for it, so repeated names and values skip validation and toLowerCase() in setHeader() and appendHeader(). Arrays are always re-validated. The cache is bounded. Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> Assisted-by: Claude
Use a two-generation LRU instead of stopping at 256 names. Wrap validation in hideStackFrames() and add a benchmark case with many unique names. Assisted-by: Claude Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Cache only one in eight new names, so most misses skip the allocation and insertion. Assisted-by: Claude Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
8c04114 to
a0bc32d
Compare
|
https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1908/ benchmark/http/set-header-rest.js |
|
@Ethan-Arrowood I ran benchmark again after rebase |
Ethan-Arrowood
left a comment
There was a problem hiding this comment.
I'm approving this, but I do want to see what other @nodejs/http members think. The many headers case regresses 6.4%, meanwhile the fixed case improves 16.3%. Is that sufficient enough to land this change? I'm not sure which scenario is more common. I also am unsure if the regression is significant enough compared to the improvement. If others believe the regression is significant enough, should we then gate this behind an option? So in circumstances where someone knows they'll have lots of header values they can disable this and not pay the cache penalty? Or better yet, could we make the cache size itself configurable? I think this is a sensible enough default in that case.
|
In real-world scenarios, most header names are fixed so I believe the gains would outweigh the regression. |
setHeader()andappendHeader()validate, lowercase, and scan the value of every header on every call, even though applications send the same names and mostly the same values on every response.This caches each valid header name with its lowercased form and the last valid string value set for it, so repeated names skip the token check and
toLowerCase(), and repeated values skip the character scan. Arrays are always re-validated since they are mutable. The cache is capped at 256 names, and values longer than 256 characters are not cached.Adds
benchmark/http/set-header-rest.jsand a regression test.