UDPSocket#send copies data multiple times #621

Closed
ghost opened this Issue Mar 31, 2013 · 1 comment

Comments

Projects
None yet
1 participant
@ghost

ghost commented Mar 31, 2013

From RubyUDPSocket.java:277

RubyString data = _mesg.convertToString();
ByteBuffer buf = ByteBuffer.wrap(data.getBytes());
byte[] buf2 = data.getBytes();

each call to data.getBytes() creates a new byte array with the contents of data and returns it - and the second copy is only needed for multicast sockets - if it is unicast, then it is unused!

This could be optimized to use data.getByteList().unsafeBytes(), and the ByteBuffer(byte[] data, int offset, int length) constructor and the DatagramPacket(byte[] data, int offset, int length) constructor to avoid any copying of the data.

@ghost ghost self-assigned this Apr 1, 2013

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Apr 5, 2016

Member

Definitely needs optimization. Looking at 9.1 to see if this is still the case.

Member

headius commented Apr 5, 2016

Definitely needs optimization. Looking at 9.1 to see if this is still the case.

@headius headius added this to the JRuby 9.1.0.0 milestone Apr 5, 2016

@headius headius closed this in 2221210 Apr 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment