Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf improvements for findDomainID()
The function findDomainID() is called a lot and contains a simple test to avoid further iteration and more expensive calls within. This commit improves the performance overall by optimizing the simple test to match more frequently and perform the actual comparison quicker too. The original code will try a quick match on the first char of the domain before continuing, which from my testing actually appears to match more regularly than expected, and therefor, continue with more expensive calls and further iteration. This is because common "domains" tend to start with things like 'www.' or 'mail. or 'img.' (etc., etc.) and also the frequency of the first letters in domains generally seems to be fairly common too. This patch implements an approach to test whether 4 chars are the same, offset 4 chars within the domain (to avoid 'www.' and similar), unless the length of the domain is less than 4 chars and we revert to the original first char only test. The 4 chars are also packed into an int sized register for comparison which means the comparison is just as fast as the single char test. My testing of these two changes on my modest Pi 3 Model B Rev 2 (the 1GB RAM, non-GbE Quad-core 1.2 GHz kind) showed an average 20% improvement in dns lookup latency (namebench showed 103ms to 83ms improvement using Alexa Top 200 domains). Signed-off-by: stuXORstu stuXORstu@gmail.com
- Loading branch information