-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Add TextEncoder.prototype.encodeInto #26904
Copy link
Copy link
Closed
Labels
bufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.encodingIssues and PRs related to the TextEncoder and TextDecoder APIs.Issues and PRs related to the TextEncoder and TextDecoder APIs.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
Metadata
Metadata
Assignees
Labels
bufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.encodingIssues and PRs related to the TextEncoder and TextDecoder APIs.Issues and PRs related to the TextEncoder and TextDecoder APIs.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.
Is your feature request related to a problem? Please describe.
TextEncoder.prototype.encodeIntois a new method available in latest Chrome and Firefox that allows efficient encoding of strings into a given buffer, avoiding intermediate allocation and copying.Its primary usecase is a more efficient way to pass strings to WASM (one of the most expensive things one has to do when communicating with JavaScript) and it's already leveraged by Rust wasm-bindgen where available. wasm-bindgen has support for a Node.js target, so it would be great to speed things up here too.
Describe the solution you'd like
Adding native
encodeIntomethod to theTextEncoderclass already available inutilmodule.Please describe the desired behavior.
MDN: https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/encodeInto
Describe alternatives you've considered
Sending PR to wasm-bindgen to wrap memory into a Node-specific
Bufferand useBuffer.prototype.writeinstead.It has very similar semantics, and produces similar speed-ups (up to 35% on some of my string-interaction-heavy WASM libraries), but I wanted to see if it's possible to solve this on the Node.js side first so that the same method could be used for all platforms.
cc @jasnell as the author of the original implementation of WHATWG Encoding API in Node.js (#13644)