string_decoder: decode UTF-8 via StringBytes::Encode · nodejs/node@f33dba7 · GitHub
Skip to content

Commit f33dba7

Browse files
codebytereaduh95
authored andcommitted
string_decoder: decode UTF-8 via StringBytes::Encode
StringDecoder used v8::String::NewFromUtf8() for UTF-8, while Buffer#toString() goes through StringBytes::Encode(), which has simdutf-backed ASCII, Latin-1 and UTF-16 paths and only falls back to NewFromUtf8() for input that contains invalid sequences. Route the decoder through the same function, so streams with setEncoding('utf8') and readline decode at the same speed as Buffer#toString(). U+FFFD replacement is unchanged because invalid input still ends up in NewFromUtf8(), and the ERR_STRING_TOO_LONG check is kept explicit so over-long input fails as before. benchmark/string_decoder/string-decoder.js (encoding=utf8) and a readline-over-pipe workload improve by 2-3x for chunks >= 1 KiB; 64 KiB newline-delimited JSON round trips over child stdio improve by ~30% on the reading side alone. Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com> PR-URL: #65324 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 89aba0c commit f33dba7

2 files changed

Lines changed: 94 additions & 15 deletions

File tree

src/string_decoder.cc

Lines changed: 13 additions & 15 deletions
Lines changed: 81 additions & 0 deletions

0 commit comments

Comments
 (0)