-
|
As discussed regarding the performance of writeHeaders, JS string transfert costs a lot (about 0.5% per string), writing 5 headers (10 strings) costs 5%. This is because the c++ wrapper actually performs a copy of the string locally. Luckily, with Node.js 24, v8 introduced the String::ValueView, which allows direct access to the string buffer as we do for binary data, giving a nice performance boost. I am implementing it and it seems to work well so far. One thing though, is that Is there anywhere in the c++ wrapper where we use NativeString and we need the data to be persistent? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
https://v8docs.nodesource.com/node-25.0/d1/d7c/classv8_1_1_string_1_1_value_view.html Let this link help us! |
Beta Was this translation helpful? Give feedback.
-
|
You can already test your hypothesis right now, by benchmarking the writeHeder using ArrayBuffers vs. Strings. So far you've not really provided any benchmarks. |
Beta Was this translation helpful? Give feedback.
Actually Node stores strings either as utf8 (99% of cases), or as utf16 if there are any utf16 characters in them.
So if the string is utf8 we can directly access ValueView.data8(), otherwise we have to copy and convert it to utf8.
I will open a draft PR with the changes, so we can test and talk about it.
The PR: #1262