Replies: 8 comments 6 replies
-
|
Hello. uWS doesn’t really force you to write one header per function call. You can use underlying CRLF string concatenation to make several requests fit into one call. #1217 here I describe my library, and in one or two days I am going to roll out @ublitzjs/core 1.1.0. There you would be able to write several headers at once, without sacrificing typescript safety.
I have to point out, that on my pc at some benchmark, where I wrote 100 headers with 100 function calls vs 100 concatenated in one call, speed raised from 130000 requests per aecond to 280000 requests per second |
Beta Was this translation helpful? Give feedback.
-
|
Well anyways, yes you could add a JS function in uws.js that uses the trick with response.writeHeader to write many headers. I guess it would be something like uWS.writeHeaders(res, [headers]) |
Beta Was this translation helpful? Give feedback.
-
|
We can let AI add writeHeaders as a test and you can benchmark it, I already added onFullData so I already broke my own rule here. Let's add it as a test only in the wrapper (it can be improved later on) |
Beta Was this translation helpful? Give feedback.
-
|
Okay I added it, now you have both onFullData and writeHeaders. Let's benchmark this and compare! |
Beta Was this translation helpful? Give feedback.
-
|
I benchmarked the writeHeaders and it absolutely sucks Two calls to writeHeader: One call to writeHeaders: |
Beta Was this translation helpful? Give feedback.
-
|
I have reverted this change |
Beta Was this translation helpful? Give feedback.
-
|
So here I am again. Even though in runtime using CRLF trick is unsafe (but faster than writeHeaders or singular writeHeader), “preparing” headers can be done easily. @ublitzjs/core 1.1.0 has rolled out, as well as its “staticHeaders” function. |
Beta Was this translation helpful? Give feedback.
-
|
I tested using CRLF trick and a js helper function writeHeaders. Results: Test 5 headers: Test 10 headers: Test 20 headers: Sending multiple strings costs a lot, and that's where we lose the most performance. I don't know if this helper function should be added or not to the uws.js file. Alternatively, we could add a writeRawHeaders(RecognizedString) function, it would allow for caching and optimizations. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Woud it be possible to get a writeHeaders function?
Signature could be [[key: string, value: string]]
So we only need one function/c++ call to write all headers.
Beta Was this translation helpful? Give feedback.
All reactions