From e7c5e16b9b4f75da948f6d27e8de19d7a149548e Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Mon, 7 Jul 2008 14:05:29 +0000 Subject: Performance improvements: rather than calling content_clean() every poll, we now call it no more frequently than once every 5 seconds. Additionally, we cache the result of talloc_total_size() in content_clean() rather than calculating it twice. On large documents, this function took 25% of CPU time. This makes the fetching/rendering/scrolling/redrawing of large documents over twice as fast. svn path=/trunk/netsurf/; revision=4527 --- content/content.c | 5 +++-- content/content.h | 1 + desktop/netsurf.c | 11 ++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/content/content.c b/content/content.c index e4431453a..63b7f7b26 100644 --- a/content/content.c +++ b/content/content.c @@ -873,14 +873,15 @@ void content_clean(void) next = 0; for (c = content_list; c; c = c->next) { next = c; - size += c->size + talloc_total_size(c); + c->talloc_size = talloc_total_size(c); + size += c->size + c->talloc_size; } for (c = next; c && (unsigned int) option_memory_cache_size < size; c = prev) { prev = c->prev; if (c->user_list->next) continue; - size -= c->size + talloc_total_size(c); + size -= c->size + c->talloc_size; content_destroy(c); } } diff --git a/content/content.h b/content/content.h index ae43b933e..a44d36782 100644 --- a/content/content.h +++ b/content/content.h @@ -232,6 +232,7 @@ struct content { unsigned int size; /**< Estimated size of all data associated with this content, except alloced as talloc children of this. */ + off_t talloc_size; /**< Used by content_clean() */ char *title; /**< Title for browser window. */ unsigned int active; /**< Number of child fetches or conversions currently in progress. */ diff --git a/desktop/netsurf.c b/desktop/netsurf.c index cc823d4e9..822f81a77 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -121,7 +121,16 @@ void netsurf_init(int argc, char** argv) void netsurf_poll(void) { - content_clean(); + static unsigned int last_clean = 0; + unsigned int current_time = wallclock(); + + /* avoid calling content_clean() more often than once every 5 + * seconds. + */ + if (last_clean + 500 < current_time) { + last_clean = current_time; + content_clean(); + } gui_poll(fetch_active); fetch_poll(); } -- cgit v1.2.3