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

Avoid repeated costly copies of buffers when working with encoders #811

Merged
merged 2 commits into from
Jul 20, 2020

Conversation

ankon
Copy link
Contributor

@ankon ankon commented Jul 10, 2020

Instead of using Buffer.concat whenever writing into the encoder, and thereby copying the byte
contents of earlier added content potentially many times, this commit changes the encoder to use
a bigger pre-allocated buffer to write into directly. If that buffer fills up it a new one will be created
and the old contents copied into that.


This is somewhat related to #475. In our production environment I can see improvements with this change in the order of maybe ~10% less GC reclaimed bytes/s, which does help.

Instead of using `Buffer.concat` whenever writing into the encoder, and thereby copying the byte
contents of earlier added content potentially many times, this commit changes the encoder to use
a bigger pre-allocated buffer to write into directly. If that buffer fills up it a new one will be created
and the old contents copied into that.
@Nevon
Copy link
Collaborator

Nevon commented Jul 20, 2020

Cool! I've been wanting to do this forever, but never got around to finishing it up. I just have one question about the implementation, but I'm fine with merging either way.

@Nevon Nevon merged commit 6b2d723 into tulios:master Jul 20, 2020
@ankon ankon deleted the pr/encoder-avoid-copies branch July 20, 2020 13:32
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.

2 participants