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

CirceEntityEncoder: avoid intermediate ByteBuffer duplication #4124

Closed

Conversation

diesalbla
Copy link
Contributor

@diesalbla diesalbla commented Jan 2, 2021

In the EntityEncoder for Json, there is a call to the apply method of fs2.Chunk.ByteBuffer companion object, which
duplicates the given byte buffer. By default, the printer from circe generates a new ByteBuffer for each Json, so we do not need to duplicate it. WE avoid it by calling the view method instead.

This should save memory allocations proportional to the size of the response.

@diesalbla diesalbla closed this Jan 2, 2021
@diesalbla diesalbla reopened this Jan 2, 2021
The EntityEncoder for Circe Json library calls the
`apply` method of the `Chunk.ByteBuffer` class, which
_duplicates_ the given ByteBuffer. Since the `circe` printer
generates a distinct ByteBuffer for each Json, we do not need that
duplication and so call to the `view` method instead.
@diesalbla diesalbla force-pushed the circeentityencoder_save_array branch from 64153b9 to 0fcac7d Compare January 2, 2021 12:26
Copy link
Member

@cquiroz cquiroz left a comment

Choose a reason for hiding this comment

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

LGTM

@rossabaker
Copy link
Member

Good find. I'm going to cherry-pick this back to 0.21.

rossabaker pushed a commit that referenced this pull request Jan 2, 2021
The EntityEncoder for Circe Json library calls the
`apply` method of the `Chunk.ByteBuffer` class, which
_duplicates_ the given ByteBuffer. Since the `circe` printer
generates a distinct ByteBuffer for each Json, we do not need that
duplication and so call to the `view` method instead.
@rossabaker rossabaker closed this Jan 2, 2021
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.

None yet

4 participants