You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TLDR;
Currently, passing ArrayBuffer data from Devvit to a WebView requires converting it to a base64 string. This workaround significantly increases data size and reduces performance due to unnecessary cloning and data encoding.
Description:
Forwarding raw arrayBuffer received with a fetch request from devvit to the Webview is a great performance improvement, currently the only workaround is to convert data as a base 64 string, which clones and expand the data size.
Transferable objects are commonly used to share resources that can only be safely exposed to a single JavaScript thread at a time. For example, an ArrayBuffer is a transferable object that owns a block of memory. When such a buffer is transferred between threads, the associated memory resource is detached from the original buffer and attached to the buffer object created in the new thread.
The correct solution would be to forward the third argument of postMessage function:
transfer
An optional array of transferable objects to transfer ownership of. The ownership of these objects is given to the destination side and they are no longer usable on the sending side. These transferable objects should be attached to the message; otherwise they would be moved but not actually accessible on the receiving end.
Today, passing an arrayBuffer via postMessage will make it not accessible from within the Webview for the reason above.
The solution would be to change the signature of the postMessage function in UseWebViewResult from: postMessage(message: To): void;
to: postMessage(message: To, transfer?: Transferable[]): void;
The text was updated successfully, but these errors were encountered:
TLDR;
Currently, passing ArrayBuffer data from Devvit to a WebView requires converting it to a base64 string. This workaround significantly increases data size and reduces performance due to unnecessary cloning and data encoding.
Description:
Forwarding raw arrayBuffer received with a fetch request from devvit to the Webview is a great performance improvement, currently the only workaround is to convert data as a base 64 string, which clones and expand the data size.
The correct solution would be to forward the third argument of postMessage function:
Today, passing an arrayBuffer via postMessage will make it not accessible from within the Webview for the reason above.
The solution would be to change the signature of the
postMessage
function inUseWebViewResult
from:postMessage(message: To): void;
to:
postMessage(message: To, transfer?: Transferable[]): void;
The text was updated successfully, but these errors were encountered: