[nautilus/wip/csoriano/flow] icon-view: improve performance



commit ea4b6337d6d7611ffab9567f8f2c0881da3d012a
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu May 12 18:09:07 2016 +0200

    icon-view: improve performance
    
    Add files in batch.
    
    Some numbers:
    canvas-view for 10.000 files: 0.02 s
    icon-view: 22 s
    icon-view with files in batch: 12 s

 src/nautilus-files-view.c |   19 +++++++++++++++++--
 src/nautilus-files-view.h |    6 ++++++
 src/nautilus-icon-view.c  |   40 ++++++++++++++++++++++++++++++++++------
 3 files changed, 57 insertions(+), 8 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 7bd3924..c7a7e4f 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -128,6 +128,7 @@
 
 enum {
         ADD_FILE,
+        ADD_FILES,
         BEGIN_FILE_CHANGES,
         BEGIN_LOADING,
         CLEAR,
@@ -3564,6 +3565,7 @@ process_old_files (NautilusFilesView *view)
         GList *files_added, *files_changed, *node;
         FileAndDirectory *pending;
         GList *selection, *files;
+        g_autoptr (GList) pending_additions = NULL;
 
         files_added = view->details->old_added_files;
         files_changed = view->details->old_changed_files;
@@ -3576,8 +3578,8 @@ process_old_files (NautilusFilesView *view)
 
                 for (node = files_added; node != NULL; node = node->next) {
                         pending = node->data;
-                        g_signal_emit (view,
-                                       signals[ADD_FILE], 0, pending->file, pending->directory);
+                        pending_additions = g_list_prepend (pending_additions,
+                                                            pending->file);
                         /* Acknowledge the files that were pending to be revealed */
                         if (g_hash_table_contains (view->details->pending_reveal, pending->file)) {
                                 g_hash_table_insert (view->details->pending_reveal,
@@ -3585,6 +3587,11 @@ process_old_files (NautilusFilesView *view)
                                                      GUINT_TO_POINTER (TRUE));
                         }
                 }
+                if (files_added != NULL)
+                  {
+                    g_signal_emit (view,
+                                   signals[ADD_FILES], 0, pending_additions, pending->directory);
+                  }
 
                 for (node = files_changed; node != NULL; node = node->next) {
                         gboolean should_show_file;
@@ -7936,6 +7943,14 @@ nautilus_files_view_class_init (NautilusFilesViewClass *klass)
                               NULL, NULL,
                               g_cclosure_marshal_generic,
                               G_TYPE_NONE, 2, NAUTILUS_TYPE_FILE, NAUTILUS_TYPE_DIRECTORY);
+        signals[ADD_FILES] =
+                g_signal_new ("add-files",
+                              G_TYPE_FROM_CLASS (klass),
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (NautilusFilesViewClass, add_files),
+                              NULL, NULL,
+                              g_cclosure_marshal_generic,
+                              G_TYPE_NONE, 2, G_TYPE_POINTER, NAUTILUS_TYPE_DIRECTORY);
         signals[BEGIN_FILE_CHANGES] =
                 g_signal_new ("begin-file-changes",
                               G_TYPE_FROM_CLASS (klass),
diff --git a/src/nautilus-files-view.h b/src/nautilus-files-view.h
index 9b5a28b..8469b90 100644
--- a/src/nautilus-files-view.h
+++ b/src/nautilus-files-view.h
@@ -87,6 +87,12 @@ struct NautilusFilesViewClass {
         void    (* add_file)                    (NautilusFilesView *view,
                                                  NautilusFile      *file,
                                                  NautilusDirectory *directory);
+        /* The 'add_files' signal is emitted to add a set of files to the view.
+         * It must be replaced by each subclass.
+         */
+        void    (* add_files)                    (NautilusFilesView *view,
+                                                  GList             *files,
+                                                  NautilusDirectory *directory);
         void    (* remove_file)                 (NautilusFilesView *view,
                                                  NautilusFile      *file,
                                                  NautilusDirectory *directory);
diff --git a/src/nautilus-icon-view.c b/src/nautilus-icon-view.c
index 35255bd..62b66ee 100644
--- a/src/nautilus-icon-view.c
+++ b/src/nautilus-icon-view.c
@@ -233,17 +233,45 @@ real_sort_directories_first_changed (NautilusFilesView *self)
 {
 }
 
+static gpointer*
+convert_glist_to_array (GList *list)
+{
+  gpointer *array;
+  GList *l;
+  int i = 0;
+
+  g_return_val_if_fail (list != NULL, NULL);
+
+  array = g_malloc (g_list_length (list) * sizeof (list->data));
+
+  for (l = list; l != NULL; l = l->next, i++)
+    {
+      array[i] = l->data;
+    }
+
+  return array;
+}
+
 static void
-real_add_file (NautilusFilesView *self,
-               NautilusFile      *file,
-               NautilusDirectory *directory)
+real_add_files (NautilusFilesView *self,
+                GList             *files,
+                NautilusDirectory *directory)
 {
   NautilusIconViewPrivate *priv;
+  g_autofree gpointer *array = NULL;
 
   priv = nautilus_icon_view_get_instance_private (self);
 
-  g_print ("add file %d\n", g_list_model_get_n_items (priv->model));
-  g_list_store_append (G_LIST_STORE (priv->model), file);
+  clock_t start = clock() ;
+
+  g_print ("add file %d\n", g_list_length (files));
+  array = convert_glist_to_array (files);
+  g_list_store_splice (G_LIST_STORE (priv->model),
+                       g_list_model_get_n_items (priv->model),
+                       0, array, g_list_length (files));
+  clock_t end = clock() ;
+  double elapsed_time = (end-start)/(double)CLOCKS_PER_SEC ;
+  g_print ("add file finished %d %f\n", g_list_model_get_n_items (priv->model), elapsed_time);
 }
 
 
@@ -433,7 +461,7 @@ nautilus_icon_view_class_init (NautilusIconViewClass *klass)
 
   object_class->finalize = nautilus_icon_view_finalize;
 
-  files_view_class->add_file = real_add_file;
+  files_view_class->add_files = real_add_files;
   files_view_class->begin_loading = real_begin_loading;
   files_view_class->bump_zoom_level = real_bump_zoom_level;
   files_view_class->can_zoom_in = real_can_zoom_in;


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