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

Use toByteBuffer in ByteChunkAbsorbable to avoid allocating an array #376

Merged
merged 1 commit into from
Oct 2, 2022

Conversation

CremboC
Copy link
Contributor

@CremboC CremboC commented Sep 22, 2022

The latest version of fs2 has an efficient toByteBuffer method, which maybe be executed in O(1) time and space if the subtype of Chunk happens to be the correct one. If it's the wrong subtype, it fallbacks to the same toArray method the current jawn-fs2 code uses.

This should result in reduced CPU usage and lower memory usage as we're no longer allocating a whole new byte array and not copying over the data.

Note jawn AsyncParser already has a absorb(b: ByteBuffer) so nothing needs to change on that end.

https://github.com/typelevel/fs2/blob/1f5f2310456b18fb1e5f23e31b24ff387797d3eb/core/shared/src/main/scala/fs2/Chunk.scala#L305-L319

Note this should synergise with typelevel/fs2#2990.

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

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

Good find.

@rossabaker rossabaker merged commit 298a9ae into typelevel:main Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants