Skip to content

Stream DNS: try to handle incoming data directly - avoid memory copying/buffer resizing when reading data

Artem Boldariev requested to merge artem-streamdns-avoid-copying-on-reading into main

This commit optimises isc_dnsstream_assembler_t in such a way that memory copying and reallocation are avoided when receiving one or more complete DNS messages at once. We try to handle the data from the messages directly, without storing them in an intermediate memory buffer.

In particular, the following cases are optimised:

  • There is no data in the internal buffer - try to handle incoming messages directly, avoiding copying memory if possible;
  • There is partial message available in the internal buffer - try to copy enough data into the buffer to handle it, then try to handle the rest directly, without copying.

N.B.

The fact that similar optimisations are possible was mentioned in the comments in old transports superseded by StreamDNS. However, due to the way how they were structured, it was rather hard to implement that. Having a separate entity dedicated for handling incoming DNS messages makes is easier.

Merge request reports