[gthumb] fixed a perfomance regression due to the GSettings porting



commit 57ff462dddc462534c14860ab25907cb7aca4de7
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Nov 24 09:54:23 2011 +0100

    fixed a perfomance regression due to the GSettings porting
    
    pass the whole file list to the 'read-metadata-ready' hook callbacks
    to avoid to create and destroy a GSettings object for each file.

 extensions/comments/main.c      |  214 ++++++++++++++++++++-------------------
 gthumb/gth-file-list.c          |    4 +
 gthumb/gth-file-source-vfs.c    |    4 +
 gthumb/gth-grid-view.c          |    9 +-
 gthumb/gth-main-default-hooks.c |    2 +-
 gthumb/gth-metadata-provider.c  |   14 ++-
 6 files changed, 131 insertions(+), 116 deletions(-)
---
diff --git a/extensions/comments/main.c b/extensions/comments/main.c
index 1494eba..55daf98 100644
--- a/extensions/comments/main.c
+++ b/extensions/comments/main.c
@@ -77,19 +77,13 @@ comments__add_sidecars_cb (GFile  *file,
 
 
 static void
-comments__read_metadata_ready_cb (GthFileData *file_data,
-				  const char  *attributes)
+comments__read_metadata_ready_cb (GList      *file_list,
+				  const char *attributes)
 {
-	GSettings     *settings;
-	gboolean       store_metadata_in_files;
-	gboolean       synchronize;
-	gboolean       write_comment;
-	GthMetadata   *metadata;
-	GthStringList *comment_categories;
-	GList         *scan;
-	const char    *text;
-	GthComment    *comment;
-	GthStringList *categories;
+	GSettings *settings;
+	gboolean   store_metadata_in_files;
+	GList     *scan;
+	gboolean   synchronize;
 
 	settings = g_settings_new (GTHUMB_GENERAL_SCHEMA);
 	store_metadata_in_files = g_settings_get_boolean (settings, PREF_GENERAL_STORE_METADATA_IN_FILES);
@@ -102,7 +96,8 @@ comments__read_metadata_ready_cb (GthFileData *file_data,
 		 * Give priority to the .comment metadata which, if present,
 		 * is the most up-to-date. */
 
-		gth_comment_update_general_attributes (file_data);
+		for (scan = file_list; scan; scan = scan->next)
+			gth_comment_update_general_attributes ((GthFileData *) scan->data);
 
 		return;
 	}
@@ -114,119 +109,130 @@ comments__read_metadata_ready_cb (GthFileData *file_data,
 	if (! synchronize)
 		return;
 
-	write_comment = FALSE;
+	for (scan = file_list; scan; scan = scan->next) {
+		GthFileData   *file_data = scan->data;
+		gboolean       write_comment;
+		GthMetadata   *metadata;
+		GthStringList *comment_categories;
+		GList         *scan;
+		const char    *text;
+		GthComment    *comment;
+		GthStringList *categories;
 
-	comment = gth_comment_new ();
-	gth_comment_set_note (comment, g_file_info_get_attribute_string (file_data->info, "comment::note"));
-	gth_comment_set_caption (comment, g_file_info_get_attribute_string (file_data->info, "comment::caption"));
-	gth_comment_set_place (comment, g_file_info_get_attribute_string (file_data->info, "comment::place"));
+		write_comment = FALSE;
 
-	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "comment::time");
-	if (metadata != NULL)
-		gth_comment_set_time_from_exif_format (comment, gth_metadata_get_raw (metadata));
+		comment = gth_comment_new ();
+		gth_comment_set_note (comment, g_file_info_get_attribute_string (file_data->info, "comment::note"));
+		gth_comment_set_caption (comment, g_file_info_get_attribute_string (file_data->info, "comment::caption"));
+		gth_comment_set_place (comment, g_file_info_get_attribute_string (file_data->info, "comment::place"));
 
-	comment_categories = (GthStringList *) g_file_info_get_attribute_object (file_data->info, "comment::categories");
-	if (comment_categories != NULL)
-		for (scan = gth_string_list_get_list (comment_categories); scan; scan = scan->next)
-			gth_comment_add_category (comment, (char *) scan->data);
+		metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "comment::time");
+		if (metadata != NULL)
+			gth_comment_set_time_from_exif_format (comment, gth_metadata_get_raw (metadata));
 
-	gth_comment_set_rating (comment, g_file_info_get_attribute_int32 (file_data->info, "comment::rating"));
+		comment_categories = (GthStringList *) g_file_info_get_attribute_object (file_data->info, "comment::categories");
+		if (comment_categories != NULL)
+			for (scan = gth_string_list_get_list (comment_categories); scan; scan = scan->next)
+				gth_comment_add_category (comment, (char *) scan->data);
 
-	/* sync embedded data and .comment data if required */
+		gth_comment_set_rating (comment, g_file_info_get_attribute_int32 (file_data->info, "comment::rating"));
 
-	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::description");
-	if (metadata != NULL) {
-		text = g_file_info_get_attribute_string (file_data->info, "comment::note");
-		if (! dom_str_equal (gth_metadata_get_formatted (metadata), text)) {
-			gth_comment_set_note (comment, gth_metadata_get_formatted (metadata));
-			write_comment = TRUE;
-		}
-	}
+		/* sync embedded data and .comment data if required */
 
-	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::title");
-	if (metadata != NULL) {
-		text = g_file_info_get_attribute_string (file_data->info, "comment::caption");
-		if (! dom_str_equal (gth_metadata_get_formatted (metadata), text)) {
-			gth_comment_set_caption (comment, gth_metadata_get_formatted (metadata));
-			write_comment = TRUE;
+		metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::description");
+		if (metadata != NULL) {
+			text = g_file_info_get_attribute_string (file_data->info, "comment::note");
+			if (! dom_str_equal (gth_metadata_get_formatted (metadata), text)) {
+				gth_comment_set_note (comment, gth_metadata_get_formatted (metadata));
+				write_comment = TRUE;
+			}
 		}
-	}
 
-	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::location");
-	if (metadata != NULL) {
-		text = g_file_info_get_attribute_string (file_data->info, "comment::place");
-		if (! dom_str_equal (gth_metadata_get_formatted (metadata), text)) {
-			gth_comment_set_place (comment, gth_metadata_get_formatted (metadata));
-			write_comment = TRUE;
+		metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::title");
+		if (metadata != NULL) {
+			text = g_file_info_get_attribute_string (file_data->info, "comment::caption");
+			if (! dom_str_equal (gth_metadata_get_formatted (metadata), text)) {
+				gth_comment_set_caption (comment, gth_metadata_get_formatted (metadata));
+				write_comment = TRUE;
+			}
 		}
-	}
 
-	metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::datetime");
-	if (metadata != NULL) {
-		text = gth_metadata_get_raw (metadata);
-		metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "comment::time");
+		metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::location");
 		if (metadata != NULL) {
-			if (! dom_str_equal (gth_metadata_get_raw (metadata), text)) {
-				gth_comment_set_time_from_exif_format (comment, gth_metadata_get_raw (metadata));
+			text = g_file_info_get_attribute_string (file_data->info, "comment::place");
+			if (! dom_str_equal (gth_metadata_get_formatted (metadata), text)) {
+				gth_comment_set_place (comment, gth_metadata_get_formatted (metadata));
 				write_comment = TRUE;
 			}
 		}
-	}
 
-	categories = (GthStringList *) g_file_info_get_attribute_object (file_data->info, "general::tags");
-	if (categories != NULL) {
-		comment_categories = (GthStringList *) g_file_info_get_attribute_object (file_data->info, "comment::categories");
-		if (! gth_string_list_equal (categories, comment_categories)) {
-			GList *scan;
+		metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "general::datetime");
+		if (metadata != NULL) {
+			text = gth_metadata_get_raw (metadata);
+			metadata = (GthMetadata *) g_file_info_get_attribute_object (file_data->info, "comment::time");
+			if (metadata != NULL) {
+				if (! dom_str_equal (gth_metadata_get_raw (metadata), text)) {
+					gth_comment_set_time_from_exif_format (comment, gth_metadata_get_raw (metadata));
+					write_comment = TRUE;
+				}
+			}
+		}
+
+		categories = (GthStringList *) g_file_info_get_attribute_object (file_data->info, "general::tags");
+		if (categories != NULL) {
+			comment_categories = (GthStringList *) g_file_info_get_attribute_object (file_data->info, "comment::categories");
+			if (! gth_string_list_equal (categories, comment_categories)) {
+				GList *scan;
 
-			gth_comment_clear_categories (comment);
-			for (scan = gth_string_list_get_list (categories); scan; scan = scan->next)
-				gth_comment_add_category (comment, scan->data);
-			write_comment = TRUE;
+				gth_comment_clear_categories (comment);
+				for (scan = gth_string_list_get_list (categories); scan; scan = scan->next)
+					gth_comment_add_category (comment, scan->data);
+				write_comment = TRUE;
+			}
 		}
-	}
 
-	if (write_comment) {
-		GFile *comment_file;
-		GFile *comment_directory;
-		char  *buffer;
-		gsize  size;
-
-		comment_file = gth_comment_get_comment_file (file_data->file);
-		comment_directory = g_file_get_parent (comment_file);
-		if (! g_file_query_exists (comment_directory, NULL))
-			g_file_make_directory (comment_directory, NULL, NULL);
-
-		buffer = gth_comment_to_data (comment, &size);
-		g_write_file (comment_file,
-			      FALSE,
-			      G_FILE_CREATE_NONE,
-			      buffer,
-			      size,
-			      NULL,
-			      NULL);
-
-		{
-			GFile *parent;
-			GList *list;
-
-			parent = g_file_get_parent (file_data->file);
-			list = g_list_prepend (NULL, file_data->file);
-			gth_monitor_folder_changed (gth_main_get_default_monitor (),
-						    parent,
-						    list,
-						    GTH_MONITOR_EVENT_CHANGED);
-
-			g_list_free (list);
-			g_object_unref (parent);
+		if (write_comment) {
+			GFile *comment_file;
+			GFile *comment_directory;
+			char  *buffer;
+			gsize  size;
+
+			comment_file = gth_comment_get_comment_file (file_data->file);
+			comment_directory = g_file_get_parent (comment_file);
+			if (! g_file_query_exists (comment_directory, NULL))
+				g_file_make_directory (comment_directory, NULL, NULL);
+
+			buffer = gth_comment_to_data (comment, &size);
+			g_write_file (comment_file,
+				      FALSE,
+				      G_FILE_CREATE_NONE,
+				      buffer,
+				      size,
+				      NULL,
+				      NULL);
+
+			{
+				GFile *parent;
+				GList *list;
+
+				parent = g_file_get_parent (file_data->file);
+				list = g_list_prepend (NULL, file_data->file);
+				gth_monitor_folder_changed (gth_main_get_default_monitor (),
+							    parent,
+							    list,
+							    GTH_MONITOR_EVENT_CHANGED);
+
+				g_list_free (list);
+				g_object_unref (parent);
+			}
+
+			g_free (buffer);
+			g_object_unref (comment_directory);
+			g_object_unref (comment_file);
 		}
 
-		g_free (buffer);
-		g_object_unref (comment_directory);
-		g_object_unref (comment_file);
+		g_object_unref (comment);
 	}
-
-	g_object_unref (comment);
 }
 
 
diff --git a/gthumb/gth-file-list.c b/gthumb/gth-file-list.c
index f5a4a8b..e37d7c7 100644
--- a/gthumb/gth-file-list.c
+++ b/gthumb/gth-file-list.c
@@ -829,6 +829,8 @@ gfl_add_files (GthFileList *file_list,
 	GList        *scan;
 	char         *cache_base_uri;
 
+	performance (DEBUG_INFO, "gfl_add_files start");
+
 	file_store = (GthFileStore*) gth_file_view_get_model (GTH_FILE_VIEW (file_list->priv->view));
 
 	cache_base_uri = g_strconcat (get_home_uri (), "/.thumbnails", NULL);
@@ -871,6 +873,8 @@ gfl_add_files (GthFileList *file_list,
 
 	gth_file_store_exec_add (file_store, position);
 	_gth_file_list_update_pane (file_list);
+
+	performance (DEBUG_INFO, "gfl_add_files end");
 }
 
 
diff --git a/gthumb/gth-file-source-vfs.c b/gthumb/gth-file-source-vfs.c
index da82a4c..0065f8e 100644
--- a/gthumb/gth-file-source-vfs.c
+++ b/gthumb/gth-file-source-vfs.c
@@ -218,6 +218,8 @@ fec__done_func (GError   *error,
 {
 	GthFileSourceVfs *file_source_vfs = user_data;
 
+	performance (DEBUG_INFO, "gth_file_source_vfs_for_each_child end");
+
 	gth_file_source_set_active (GTH_FILE_SOURCE (file_source_vfs), FALSE);
 	file_source_vfs->priv->ready_func (G_OBJECT (file_source_vfs),
 					   error,
@@ -294,6 +296,8 @@ gth_file_source_vfs_for_each_child (GthFileSource        *file_source,
 	g_cancellable_reset (gth_file_source_get_cancellable (file_source));
 	g_hash_table_remove_all (file_source_vfs->priv->hidden_files);
 
+	performance (DEBUG_INFO, "gth_file_source_vfs_for_each_child start");
+
 	file_source_vfs->priv->start_dir_func = start_dir_func;
 	file_source_vfs->priv->for_each_file_func = for_each_file_func;
 	file_source_vfs->priv->ready_func = ready_func;
diff --git a/gthumb/gth-grid-view.c b/gthumb/gth-grid-view.c
index d26ca30..5ea8d06 100644
--- a/gthumb/gth-grid-view.c
+++ b/gthumb/gth-grid-view.c
@@ -929,11 +929,10 @@ _gth_grid_view_queue_relayout_from_line (GthGridView *self,
 		return;
 	}
 
-	if (self->priv->layout_timeout != 0)
-		g_source_remove (self->priv->layout_timeout);
-	self->priv->layout_timeout = g_timeout_add (LAYOUT_DELAY,
-						    _gth_grid_view_relayout_cb,
-						    self);
+	if (self->priv->layout_timeout == 0)
+		self->priv->layout_timeout = g_timeout_add (LAYOUT_DELAY,
+							    _gth_grid_view_relayout_cb,
+							    self);
 }
 
 
diff --git a/gthumb/gth-main-default-hooks.c b/gthumb/gth-main-default-hooks.c
index 87fa999..3a0c26e 100644
--- a/gthumb/gth-main-default-hooks.c
+++ b/gthumb/gth-main-default-hooks.c
@@ -210,7 +210,7 @@ gth_main_register_default_hooks (void)
 	 * Called after a file metadata has been read.  Used to syncronize
 	 * embedded metadata with the .comment file.
 	 *
-	 * @file_data (GthFileData *): the file
+	 * @file_list (GList *): list of GthFileData
 	 * @attributes (const char *): the attributes read for the file
 	 */
 	gth_hook_register ("read-metadata-ready", 2);
diff --git a/gthumb/gth-metadata-provider.c b/gthumb/gth-metadata-provider.c
index 88c595b..5c06085 100644
--- a/gthumb/gth-metadata-provider.c
+++ b/gthumb/gth-metadata-provider.c
@@ -159,6 +159,8 @@ _g_query_metadata_async_thread (GSimpleAsyncResult *result,
 	GList              *scan;
 	GError             *error = NULL;
 
+	performance (DEBUG_INFO, "_g_query_metadata_async_thread start");
+
 	qmd = g_simple_async_result_get_op_res_gpointer (result);
 
 	providers = NULL;
@@ -185,17 +187,17 @@ _g_query_metadata_async_thread (GSimpleAsyncResult *result,
 
 	_g_object_list_unref (providers);
 
-	if (error == NULL) {
-		for (scan = qmd->files; scan; scan = scan->next) {
-			GthFileData *file_data = scan->data;
-			gth_hook_invoke ("read-metadata-ready", file_data, qmd->attributes);
-		}
-	}
+	performance (DEBUG_INFO, "_g_query_metadata_async_thread before read-metadata-ready");
+
+	if (error == NULL)
+		gth_hook_invoke ("read-metadata-ready", qmd->files, qmd->attributes);
 
 	if (error != NULL) {
 		g_simple_async_result_set_from_error (result, error);
 		g_error_free (error);
 	}
+
+	performance (DEBUG_INFO, "_g_query_metadata_async_thread end");
 }
 
 



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