<div dir="ltr">Hi Simon and dnsmasq contributors,<br><br>I am running dnsmasq with a blocklist from<br><a href="https://github.com/notracking/hosts-blocklists/blob/master/dnsmasq/dnsmasq.blacklist.txt">https://github.com/notracking/hosts-blocklists/blob/master/dnsmasq/dnsmasq.blacklist.txt</a><br><br>I have noticed that building dnsmasq with libidn2 support (which my distro does) can cause extreme slowdowns. The slowdowns seem to come from the call to idn2_to_ascii_lz in canonicalise() being very slow.<br><br>idn2_to_ascii_lz is run on every domain name in the blocklist to encode special characters, and this is surprisingly slow even when there are no special characters. I developed a patch (attached to this email) that checks a domain name for other characters than . - a-z 0-9. If any such character is found, the domain name will be encoded. If no such character is found the domain name will not be encoded (as encoding won't change it). This removes most of the overhead of using libidn2. Unless you find any problems with this approach, I wish the patch can be mainlined.<br><br>Some benchmarks on a Raspberry Pi (slow, but probably not an uncommon device for running dnsmasq) running ArchLinux and dnsmasq git master:<br><br># Without libidn2: Acceptable speed<br>> make<br>> time ./src/dnsmasq -C dnsmasq.blacklist.txt --test<br>dnsmasq: syntax check OK.<br><br>real        0m3.699s<br>user  0m3.468s<br>sys   0m0.200s<br><br><br><br># With libidn2: To slow to be usable<br>> make COPTS="-DHAVE_LIBIDN2"<br>> time ./src/dnsmasq -C dnsmasq.blacklist.txt --test<br>dnsmasq: syntax check OK.<br><br>real    1m6.921s<br>user  0m59.509s<br>sys  0m0.606s<br><br><br># With libidn2 and attached patch: Back to acceptable speed<br>> git am 0001-Avoid-IDN-translations-when-not-needed.patch<br>> make COPTS="-DHAVE_LIBIDN2"<br>> time ./src/dnsmasq -C dnsmasq.blacklist.txt --test<br>dnsmasq: syntax check OK.<br><br>real        0m3.903s<br>user  0m3.643s<br>sys   0m0.219s<br><div><br></div><div>Best regards,</div><div>Gustaf</div></div>