[evolution] Bug #679382 - Saving attachments takes too long, maxes CPU usage



commit f568645ff6bc2a66db8ca7dc0b483569199d0e87
Author: Milan Crha <mcrha redhat com>
Date:   Thu Sep 6 14:34:46 2012 +0200

    Bug #679382 - Saving attachments takes too long, maxes CPU usage

 widgets/misc/e-attachment.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c
index b83bf1c..315b012 100644
--- a/widgets/misc/e-attachment.c
+++ b/widgets/misc/e-attachment.c
@@ -66,6 +66,7 @@ struct _EAttachmentPrivate {
 	guint emblem_timeout_id;
 	gchar *disposition;
 	gint percent;
+	gint64 last_percent_notify; /* to avoid excessive notifications */
 
 	guint can_show : 1;
 	guint loading  : 1;
@@ -415,6 +416,7 @@ attachment_set_loading (EAttachment *attachment,
 
 	attachment->priv->percent = 0;
 	attachment->priv->loading = loading;
+	attachment->priv->last_percent_notify = 0;
 
 	g_object_freeze_notify (G_OBJECT (attachment));
 	g_object_notify (G_OBJECT (attachment), "percent");
@@ -434,6 +436,7 @@ attachment_set_saving (EAttachment *attachment,
 {
 	attachment->priv->percent = 0;
 	attachment->priv->saving = saving;
+	attachment->priv->last_percent_notify = 0;
 
 	g_object_freeze_notify (G_OBJECT (attachment));
 	g_object_notify (G_OBJECT (attachment), "percent");
@@ -446,14 +449,24 @@ attachment_progress_cb (goffset current_num_bytes,
                         goffset total_num_bytes,
                         EAttachment *attachment)
 {
+	gint new_percent;
+
 	/* Avoid dividing by zero. */
 	if (total_num_bytes == 0)
 		return;
 
-	attachment->priv->percent =
-		(current_num_bytes * 100) / total_num_bytes;
+	/* do not notify too often, 5 times per second is sufficient */
+	if (g_get_monotonic_time () - attachment->priv->last_percent_notify < 200000)
+		return;
 
-	g_object_notify (G_OBJECT (attachment), "percent");
+	attachment->priv->last_percent_notify = g_get_monotonic_time ();
+
+	new_percent = (current_num_bytes * 100) / total_num_bytes;
+
+	if (new_percent != attachment->priv->percent) {
+		attachment->priv->percent = new_percent;
+		g_object_notify (G_OBJECT (attachment), "percent");
+	}
 }
 
 static gboolean



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]