Zonec: b64_pton performance

Hello,

during my tests of NSD I've found a bottleneck in "zonec" that is easy
to fix and has significant performance impact for signed zones. This
bottleneck is b64_pton in /compat/b64_pton.c. Because signed zonefiles
are full of base64-encoded RRSIG/DNSKEY records, base64 decoder
performance really matters here. Unfortunately, b64_pton implementation
shipped with NSD is quite poor. It calls strchr(Base64,ch) for every
input character, its fast path contains too many branches etc. Attached
I send a patch that fixes it. The patch precomputes a reverse mapping
table of base64 characters to avoid strchr and simplifies tests of
whitespaces and padding characters. It also splits b64_pton into two
functions, one for non-NULL target and the other for NULL target. Maybe
the function for NULL target could be omitted, but I wanted to keep 100%
compatibility with the original b64_pton. I welcome any comments
regarding it.

Test environment: ~65000 signed zones of our customers, 64-bit Gentoo
Linux, NSD 3.2.4, gcc 4.3.2, Intel Xeon X3350 @ 2.66GHz, all zone files
pre-cached in memory.

Before:
$ time zonec
real 0m40.098s (+- 0.1s)
user 0m38.264s
sys 0m1.797s

After:
$ time zonec
real 0m28.056s (+- 0.2s)
user 0m26.285s
sys 0m1.703s

That is 30% improvement of zonec compilation time in our case.

Best regards

Martin Svec

(attachments)

b64-pton-optim.patch (5.96 KB)

Hello, attached I send a new version of the patch that fixes the
following gcc warning:

./compat/b64_pton.c: In function 'b64_initialize_rmap':
./compat/b64_pton.c:164: warning: array subscript has type 'char'

Paul, thanks for your report.

Regards

Martin Svec

(attachments)

b64-pton-optim.patch (5.96 KB)