Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly optimize binary reader #148

Closed
timostamm opened this issue Aug 27, 2021 · 1 comment
Closed

Possibly optimize binary reader #148

timostamm opened this issue Aug 27, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@timostamm
Copy link
Owner

BinaryReader.bytes() uses slice() to extract byte field data:

return this.buf.slice(start, this.pos);

According to MDN, this creates a copy:

The slice method does not alter the original typed array, but instead returns a copy of a portion of the original typed array.

Since we do not need a copy, it should be possible to replace this with:

return new Uint8Array(this.buf.buffer, this.buf.byteOffset + start, len);

Which will not allocate additional memory and does not require a copy.

@timostamm timostamm added the enhancement New feature or request label Aug 27, 2021
@timostamm
Copy link
Owner Author

We are now using subarray() (equivalent to creating a Uint8Array like above).

timostamm added a commit that referenced this issue Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant