[netmgr] tcpdns ineffective
While reviewing some other stuff, in lib/isc/netmgr/tcp.c
there's this code:
t->region = (isc_region_t){ .base = isc_mem_get(t->mctx,
region->length + 2),
.length = region->length + 2 };
*(uint16_t *)t->region.base = htons(region->length);
memmove(t->region.base + 2, region->base, region->length);
-
the memory returned by
isc_mem_get()
isn't guaranteed to be memory aligned, so you have unaligned write to the memory here. -
doing
memmove()
just to add two bytes at the beginning of the buffer is inefficient.
Neither is to be fixed in this MR, but it should be fixed. The easiest way would be to rewrite the IO functions to work with iovec
-like buffers, similar to what uv_write()
does with uv_buf_t[]
. Then it would be easy to just add two messages here, one with length, and one with the buffer.