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

UDP reads allocate extra memory through lazy string copying #5157

Closed
andrewvc opened this issue May 3, 2018 · 2 comments
Closed

UDP reads allocate extra memory through lazy string copying #5157

andrewvc opened this issue May 3, 2018 · 2 comments

Comments

@andrewvc
Copy link

andrewvc commented May 3, 2018

Using UDP#recvfrom_nonblock(buffer_size) we've noticed that the underlying strings are the size of the buffer always, regardless of the actual message size. The strings are accurate, but rather than actually truncating the underlying byte[] JRuby simply adjusts the underlying length of the string.

When performing a large number of reads off a UDP socket with a 64k buffer size this results in a large amount of unnecessary heap being allocated.

Tested with JRuby version 9.1.13.0

@andrewvc
Copy link
Author

andrewvc commented May 3, 2018

I should mention, one workaround here is to invoke String#b, then force encode the string. That seems to force truncation.

@andrewvc
Copy link
Author

andrewvc commented May 3, 2018

Closing as this is a dupe of #5148

@andrewvc andrewvc closed this as completed May 3, 2018
@enebo enebo added this to the Invalid or Duplicate milestone May 24, 2018
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

No branches or pull requests

2 participants