Skip to content

UDPSocket#send copies data multiple times #621

@ghost

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions