Skip to content

Conversation

@edusperoni
Copy link
Contributor

WIP. Will fill details later.

Notes:

  • needs to use the alpha version of the runtime (fixes to kotlin/jvm methods)
  • need to wrap okhttp in an async task so we can process the body in the background
  • ideally be more lazy with the http processing
  • adapt the devtools agent to recieve okhttp results

other than doing some body decoding in the main thread, this implementation already covers all of the current API + cancellation. Ideeally we should have the web spec AbortController ready for this

@cla-bot cla-bot bot added the cla: yes label Oct 27, 2022
raw: result.raw,
toArrayBuffer: () => Uint8Array.from(result.raw.toByteArray()).buffer,
raw: raw,
toArrayBuffer: () => Uint8Array.from(raw.toByteArray()).buffer,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uint8Array.from iterates over each element of the source array and copies it to the new array.

If you use pass a java.nio.ByteBuffer as the argument it'll create the TypedArray from a pointer (O(1) performance and no extra memory allocation).

Creating a buffer from 1MB of data takes about ~700ms, wrapping it in a java.nio.ByteBuffer takes only 3ms

toArrayBuffer: () => {
    const arr = raw.toByteArray();
    const bb = java.nio.ByteBuffer.wrap(arr);
    const buffer = ArrayBuffer.from(bb);
    return buffer;
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants