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.71%
=======================================
Files 801 801
Lines 280705 280763 +58
Branches 54168 54200 +32
=======================================
+ Hits 254640 254699 +59
- Misses 16247 16252 +5
+ Partials 9818 9812 -6
🚀 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.
| })); | ||
|
|
||
| // Only strings are cached: arrays are mutable and must be re-validated. | ||
| const kMaxCachedHeaderNames = 256; |
There was a problem hiding this comment.
So what happens after 256? Lets add a benchmark for this case too. In some networking applications it is very common for there to be over 256 unique header names across all the requests a process might receive.
There was a problem hiding this comment.
Good question: I implemented a two-generation LRU (256 names per generation), so new names keep getting cached after the first 256, and hits are still a single Map.get().
There was a problem hiding this comment.
Only 1 in 8 new names gets admitted, so one-off names don't churn it.
There was a problem hiding this comment.
Does the benchmark result include this change too?
|
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
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.