lib: use utf8 fast path for streaming TextDecoder#61549
Conversation
a61503c to
4331d20
Compare
4331d20 to
916cd32
Compare
9ebe8ce to
111b99e
Compare
1a77e7a to
cd5c966
Compare
cd5c966 to
e9e9252
Compare
|
@ChALkeR can you run benchmark CI that applies to this pull-request? |
|
@anonrig I can't do anything until #61553 Also, we don't have a function decodeChunked(bytes) {
const chunk = 1000
const max = bytes.length - chunk
let i = 0
for (; i < max; i += chunk) decoder.decode(bytes.subarray(i, i + chunk), { stream: true })
decoder.decode(bytes.subarray(i))
}And using that instead of |
anonrig
left a comment
There was a problem hiding this comment.
Thank you for the kind responses and amazing work.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61549 +/- ##
========================================
Coverage 89.77% 89.77%
========================================
Files 672 673 +1
Lines 203755 203875 +120
Branches 39167 39190 +23
========================================
+ Hits 182922 183038 +116
- Misses 13164 13172 +8
+ Partials 7669 7665 -4
🚀 New features to boost your workflow:
|
|
@anonrig I added a benchmark for streaming Unicode TextDecoder. |
Commit Queue failed- Loading data for nodejs/node/pull/61549 ✔ Done loading data for nodejs/node/pull/61549 ----------------------------------- PR info ------------------------------------ Title lib: use utf8 fast path for streaming TextDecoder (#61549) Author Nikita Skovoroda <chalkerx@gmail.com> (@ChALkeR) Branch ChALkeR:chalker/decoder/unify/2 -> nodejs:main Labels performance, encoding, author ready, needs-ci, needs-benchmark-ci Commits 2 - lib: use utf8 fast path for streaming TextDecoder - benchmark: add streaming TextDecoder benchmark Committers 1 - Nikita Skovoroda <chalkerx@gmail.com> PR-URL: https://github.com/nodejs/node/pull/61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 27 Jan 2026 18:17:16 GMT ✔ Approvals: 3 ✔ - Yagiz Nizipli (@anonrig) (TSC): https://github.com/nodejs/node/pull/61549#pullrequestreview-3713460238 ✔ - Gürgün Dayıoğlu (@gurgunday): https://github.com/nodejs/node/pull/61549#pullrequestreview-3715962381 ✔ - Colin Ihrig (@cjihrig): https://github.com/nodejs/node/pull/61549#pullrequestreview-3717219044 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2026-01-28T15:17:24Z: https://ci.nodejs.org/job/node-test-pull-request/71102/ ℹ Last Benchmark CI on 2026-01-27T23:16:20Z: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1787 - Querying data for job/node-test-pull-request/71102/ ✔ Build data downloaded ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 61549 From https://github.com/nodejs/node * branch refs/pull/61549/merge -> FETCH_HEAD ✔ Fetched commits as 6c44d31e2522..155995438c2a -------------------------------------------------------------------------------- Auto-merging test/parallel/test-bootstrap-modules.js [main d495fa4fc6] lib: use utf8 fast path for streaming TextDecoder Author: Nikita Skovoroda <chalkerx@gmail.com> Date: Tue Jan 27 22:12:49 2026 +0400 4 files changed, 138 insertions(+), 47 deletions(-) create mode 100644 lib/internal/encoding/util.js [main 8441e884d9] benchmark: add streaming TextDecoder benchmark Author: Nikita Skovoroda <chalkerx@gmail.com> Date: Wed Jan 28 03:08:19 2026 +0400 1 file changed, 55 insertions(+) create mode 100644 benchmark/util/text-decoder-stream.js ✔ Patches applied There are 2 commits in the PR. Attempting autorebase. (node:2357) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated. (Use `node --trace-deprecation ...` to show where the warning was created) Rebasing (2/4) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- lib: use utf8 fast path for streaming TextDecoderhttps://github.com/nodejs/node/actions/runs/21576063433 |
|
Landed in 6c44d31...8c57908 |
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: #61549 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Tracking: #61041
A continuation of #61409
This is based on the logic in https://github.com/ExodusOSS/bytes
Unifies stream and non-stream codepath for UTF-8 both for intl and no-intl variants.
Previously, ICU and
string_decoderwere used on with-intl and without-intl variants correspondingly for streaming UTF-8 implementationInstead, just do minor quick slices on JS side and use the single stateless native decoding API to be fast on large chunks
This:
Benchmarks
Previously: #61131
Non-chunked, 25.5.0
Non-chunked, PR
(should not be affected)
Chunked (1000 byte chunks), 25.5.0
Chunked (1000 byte chunks), PR
The benchmark creates about ~70-256 chunks on each test
The improvement is significant