[pacman-dev] CVS update of pacman-lib/lib/libalpm (conflict.c)
Date: Tuesday, February 13, 2007 @ 21:58:36 Author: dan Path: /home/cvs-pacman/pacman-lib/lib/libalpm Modified: conflict.c (1.35 -> 1.36) Slightly optimized to remove duplicate strcmp operation. ------------+ conflict.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) Index: pacman-lib/lib/libalpm/conflict.c diff -u pacman-lib/lib/libalpm/conflict.c:1.35 pacman-lib/lib/libalpm/conflict.c:1.36 --- pacman-lib/lib/libalpm/conflict.c:1.35 Tue Feb 13 03:15:38 2007 +++ pacman-lib/lib/libalpm/conflict.c Tue Feb 13 21:58:35 2007 @@ -220,18 +220,25 @@ while(pA && pB) { const char *strA = pA->data; const char *strB = pB->data; + /* skip directories, we don't care about dir conflicts */ if(strA[strlen(strA)-1] == '/') { pA = pA->next; } else if(strB[strlen(strB)-1] == '/') { pB = pB->next; - } else if(strcmp(strA, strB) == -1) { - pA = pA->next; - } else if(strcmp(strB, strA) == -1) { - pB = pB->next; } else { - ret = alpm_list_add(ret, strdup(strA)); - pA = pA->next; - pB = pB->next; + int cmp = strcmp(strA, strB); + if(cmp < 0) { + /* item only in filesA, ignore it */ + pA = pA->next; + } else if(cmp > 0) { + /* item only in filesB, ignore it */ + pB = pB->next; + } else { + /* item in both, record it */ + ret = alpm_list_add(ret, strdup(strA)); + pA = pA->next; + pB = pB->next; + } } } for(alpm_list_t *i = ret; i; i = i->next) {
So in case you guys were curious, we used 'valgrind --tool=callgrind' to find some of these huge overuses of functions in the code. Between Aaron's changes and mine we reduced the calling of strcmp during a particular sync operation from at least 16 million calls to around 460 thousand. Here is what that looks like in kcachegrind: <http://www.archlinux.org/~dan/before_after.png>. The before is on the left, and you can see the huge block (representing time) devoted to strcmp. This block is non-existant on the right side in the fixed version. We haven't found any more of these, but if anyone else wants to tinker and monitor their pacman operations using callgrind (it does make it run significantly slower), go for it. If you notice something like we did with setlocale and strcmp taking overdue amounts of time, then let us know. -Dan
participants (2)
-
Dan McGee
-
dan@archlinux.org