# Summary

TextEncoder.encodeInto() adds encoding JavaScript strings into UTF-8
into caller-provided byte buffers. This is a performance optimization
for JavaScript/Wasm interop that allows the encoder output to be
written directly into Wasm memory without extra copies.

# Details

TextEncoder.encode() returns a DOM implementation-created buffer. This
involves coping internally in the implementation (in principle, this
copy could be optimized away with internal-only API changes) and then
yet another copy from the returned buffer into Wasm memory (optimizing
away this copy needs a Web-visible change anyway).

TextEncoder.encodeInto() avoids both copies.

https://bugzilla.mozilla.org/show_bug.cgi?id=1449849 combined with
TextEncoder.encodeInto() is expected to avoid yet more copying.

The expectation is that passing strings from JS to Wasm is / is going
to be common enough to be worthwhile to optimize.

# Bug

https://bugzilla.mozilla.org/show_bug.cgi?id=1514664

# Link to standard

https://github.com/whatwg/encoding/pull/166

# Platform coverage

All

# Estimated or target release

67

# Preference behind which this will be implemented

Not planning to have a pref for this.

# Is this feature enabled by default in sandboxed iframes?

Yes.

# DevTools bug

No need for new DevTools integration.

# Do other browser engines implement this

No, but Chrome developers have been active in the spec discussion.

# web-platform-tests

https://github.com/web-platform-tests/wpt/pull/14505

# Is this feature restricted to secure contexts?

No. This is a new method on an interface that predates restricting
features to secure contexts.

-- 
Henri Sivonen
hsivo...@mozilla.com
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to