[pacman-dev] [PATCH] Database read optimizations
Dan McGee
dan at archlinux.org
Sun Aug 28 23:27:29 EDT 2011
Hard to believe there was still more room to improve on this, but I
found an easily correctable oversight tonight. Our databases (both sync
and local) contain many blank lines, and we were not moving onto the
next line right away in these cases; instead we would proceed through
our strcmp() conditional checks as normal.
Some local numbers follow to show the effects of this patch:
Sync `-Ss foobarbaz`:
71,709 blank lines skipped early
~1,505,889 strcmp() calls avoided (21 per line)
~15% speed improvement (.210 --> .179 sec)
Local `-Qs foobarbaz`:
6,823 blank lines skipped early
115,991 strcmp() calls avoided (17 per line)
~6% speed improvement (.080 -> .071 sec)
Signed-off-by: Dan McGee <dan at archlinux.org>
---
lib/libalpm/be_local.c | 8 +++++++-
lib/libalpm/be_sync.c | 5 ++++-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 1a46dfd..be02bb5 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -580,7 +580,13 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
goto error;
}
while(!feof(fp)) {
- READ_NEXT();
+ if(fgets(line, sizeof(line), fp) == NULL && !feof(fp)) {
+ goto error;
+ }
+ if(_alpm_strip_newline(line) == 0) {
+ /* length of stripped line was zero */
+ continue;
+ }
if(strcmp(line, "%NAME%") == 0) {
READ_NEXT();
if(strcmp(line, info->name) != 0) {
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index ac99e05..12d5b7f 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -526,7 +526,10 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
int ret;
while((ret = _alpm_archive_fgets(archive, &buf)) == ARCHIVE_OK) {
char *line = buf.line;
- _alpm_strip_newline(line);
+ if(_alpm_strip_newline(line) == 0) {
+ /* length of stripped line was zero */
+ continue;
+ }
if(strcmp(line, "%NAME%") == 0) {
READ_NEXT();
--
1.7.6
More information about the pacman-dev
mailing list