Skip to content

Simplify and speed up DNS name compression

Tony Finch requested to merge fanf-compress-smaller into main

All we need for compression is a very small hash set of compression offsets, because most of the information we need (the previously added names) can be found in the message using the compression offsets.

This change combines dns_compress_find() and dns_compress_add() into one function dns_compress_name() that both finds any existing suffix, and adds any new prefix to the table. The old split led to performance problems caused by duplicate names in the compression context.

Compression contexts are now either small or large, which the caller chooses depending on the expected size of the message. There is no dynamic resizing.

There is a behaviour change: compression now acts on all the labels in each name, instead of just the last few.

A small benchmark suggests this is about 2x faster. The perflab suggests it is faster for authoritative responses, makes little difference for recursive responses, and is slower for root servers (which is what the old algorithm was optimized for). The perflab is testing the fanf-compress branch which includes this MR plus !6516 (merged)

Closes #3661 (closed)

Edited by Michał Kępień

Merge request reports