Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Conversation

@achingbrain
Copy link
Member

Buffer lists are still used internally but any Buffers created by this module are now Uint8Arrays.

BREAKING CHANGE:

  • All use of node Buffers has been replaced with Uint8Arrays

BREAKING CHANGE:

- All use of node Buffers has been replaced with Uint8Arrays
class Encoder {
constructor () {
this._pool = Buffer.allocUnsafe(POOL_SIZE)
this._pool = new Uint8Array(POOL_SIZE)
Copy link
Contributor

Choose a reason for hiding this comment

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

varint.encode(msg.data ? msg.data.length : 0, pool, offset)
offset += varint.encode.bytes

const header = pool.slice(this._poolOffset, offset)
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need to check where we're doing slices and look at using subarray instead, https://nodejs.org/api/buffer.html#buffer_buf_subarray_start_end. slice will cause a clone on TypedArrays, whereas with Buffer it will reference the same memory.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is now using subarray for the browser version.

@jacobheun
Copy link
Contributor

I created a browser specific file for encode to use Uint8Array, which will let us keep allocUnsafe for Node.js streams.

@jacobheun jacobheun merged commit d005338 into master Aug 11, 2020
@jacobheun jacobheun deleted the fix/replace-node-buffers-with-uint8arrays branch August 11, 2020 16:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants