Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: replace slice with subarray for increased performance #4210

Merged
merged 6 commits into from
Sep 23, 2022

Conversation

achingbrain
Copy link
Member

In several places we call .slice as a way to transform BufferLists to Uint8Arrays. Due to refactors in some places we are now calling .slice on Uint8Arrays which is a memory-copy operation.

In other places Uint8ArrayLists are now returned instead of BufferLists on which .slice is also a memory-copy operation.

Swap .slice for .subarray which is no-copy for Uint8Arrays and can be no-copy for Uint8ArrayLists too, where there is only a single backing buffer.

In places where we need to transform multiple Uint8ArrayLists to multiple Uint8Arrays, yield the iterators of the Uint8ArrayLists as this is also a no-copy operation.

In several places we call `.slice` as a way to transform `BufferList`s
to `Uint8Array`s. Due to refactors in some places we are now calling
`.slice` on `Uint8Array`s which is a memory-copy operation.

In other places `Uint8ArrayList`s are now returned instead of `BufferList`s
on which `.slice` is also a memory-copy operation.

Swap `.slice` for `.subarray` which is no-copy for `Uint8Array`s and
can be no-copy for `Uint8ArrayList`s too, where there is only a single
backing buffer.

In places where we need to transform multiple `Uint8ArrayList`s to
multiple `Uint8Array`s, yield the iterators of the `Uint8ArrayList`s
as this is also a no-copy operation.
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.

1 participant