]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
profiling speedups.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 18 Feb 2008 15:45:14 +0000 (15:45 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 18 Feb 2008 15:45:14 +0000 (15:45 +0000)
git-svn-id: file:///svn/unbound/trunk@963 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
util/data/dname.c
util/mini_event.c

index 29a8c13805afc03da3a1ab5d970f647ae6befe8b..7ed3215de19bfc2ce2f16c8683c28f74e5442b00 100644 (file)
@@ -8,6 +8,9 @@
        - fixup iterator operating in no cache conditions (RD flag unset
          after a CNAME).
        - streamlined code for RD flag setting.
+       - profiled code and changed dname compares to be faster. 
+         The speedup is about +3% to +8% (depending on the test).
+       - minievent tests for eintr and eagain.
 
 15 February 2008: Wouter
        - added FreeBSD rc.d script to contrib.
index 654b1c04f8fb63f08c3bed34444dcfaf233f5b8d..1b7fa2950fbf737147e5e90eea351eac676902c9 100644 (file)
@@ -91,10 +91,11 @@ dname_valid(uint8_t* dname, size_t maxlen)
        return len;
 }
 
+/** compare uncompressed, noncanonical, registers are hints for speed */
 int 
-query_dname_compare(uint8_t* d1, uint8_t* d2)
+query_dname_compare(register uint8_t* d1, register uint8_t* d2)
 {
-       uint8_t lab1, lab2;
+       register uint8_t lab1, lab2;
        log_assert(d1 && d2);
        lab1 = *d1++;
        lab2 = *d2++;
@@ -109,7 +110,9 @@ query_dname_compare(uint8_t* d1, uint8_t* d2)
                log_assert(lab1 == lab2 && lab1 != 0);
                /* compare lowercased labels. */
                while(lab1--) {
-                       if(tolower((int)*d1) != tolower((int)*d2)) {
+                       /* compare bytes first for speed */
+                       if(*d1 != *d2 && 
+                               tolower((int)*d1) != tolower((int)*d2)) {
                                if(tolower((int)*d1) < tolower((int)*d2))
                                        return -1;
                                return 1;
@@ -259,16 +262,15 @@ dname_query_hash(uint8_t* dname, hashvalue_t h)
        int i;
 
        /* preserve case of query, make hash label by label */
-       lablen = *dname;
+       lablen = *dname++;
        while(lablen) {
                log_assert(lablen <= LDNS_MAX_LABELLEN);
                labuf[0] = lablen;
-               dname++;
                i=0;
                while(lablen--)
                        labuf[++i] = (uint8_t)tolower((int)*dname++);
                h = hashlittle(labuf, labuf[0] + 1, h);
-               lablen = *dname;
+               lablen = *dname++;
        }
 
        return h;
@@ -407,11 +409,13 @@ static int
 memlowercmp(uint8_t* p1, uint8_t* p2, uint8_t len)
 {
        while(len--) {
-               if(tolower((int)*p1++) != tolower((int)*p2++)) {
-                       if(tolower((int)p1[-1]) < tolower((int)p2[-1]))
+               if(*p1 != *p2 && tolower((int)*p1) != tolower((int)*p2)) {
+                       if(tolower((int)*p1) < tolower((int)*p2))
                                return -1;
                        return 1;
                }
+               p1++;
+               p2++;
        }
        return 0;
 }
@@ -457,9 +461,7 @@ dname_lab_cmp(uint8_t* d1, int labs1, uint8_t* d2, int labs2, int* mlabs)
                        else    lastdiff = 1;
                        lastmlabs = atlabel;
                } else if((c=memlowercmp(d1, d2, len1)) != 0) { 
-                       if(c<0)
-                               lastdiff = -1;
-                       else    lastdiff = 1;
+                       lastdiff = c;
                        lastmlabs = atlabel;
                }
 
index 10179264c7f8a09f36733faedc971eb3fbcc3e99..71726277a3cc5617c7baec7af69fba20ef324b48 100644 (file)
@@ -165,6 +165,8 @@ static int handle_select(struct event_base* base, struct timeval* wait)
        memmove(&w, &base->writes, sizeof(fd_set));
 
        if((ret = select(base->maxfd+1, &r, &w, NULL, wait)) == -1) {
+               if(errno == EAGAIN || errno == EINTR)
+                       return 0;
                return -1;
        }