[gtk+/filesystemmodel: 20/28] use a sane number of files per async update again



commit 962e0a0eb1cfd36bee3e04fe294e03b66c796f5f
Author: Benjamin Otte <otte gnome org>
Date:   Mon Jun 22 13:07:31 2009 +0200

    use a sane number of files per async update again
    
    This causes significant performance regressions again, but the only wy
    to solve those is to change the way GFileEnumerator behaves.

 gtk/gtkfilesystemmodel.c |   69 +++++++++++++++++++++++++++++++++------------
 1 files changed, 50 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c
index d4cc013..e358a4a 100644
--- a/gtk/gtkfilesystemmodel.c
+++ b/gtk/gtkfilesystemmodel.c
@@ -40,7 +40,7 @@
 #define IO_PRIORITY G_PRIORITY_DEFAULT
 
 /* random number that everyone else seems to use, too */
-#define FILES_PER_QUERY 100000
+#define FILES_PER_QUERY 100
 
 typedef struct _FileModelNode           FileModelNode;
 typedef struct _GtkFileSystemModelClass GtkFileSystemModelClass;
@@ -63,6 +63,7 @@ struct _GtkFileSystemModel
   GObject               parent_instance;
 
   GFile *               dir;            /* directory that's displayed */
+  guint                 dir_thaw_source;/* GSource id for unfreezing the model */
   char *                attributes;     /* attributes the file info must contain */
   char *                full_attributes;/* attributes the file info should contain */
 
@@ -847,6 +848,17 @@ gtk_file_system_model_closed_enumerator (GObject *object, GAsyncResult *res, gpo
   g_file_enumerator_close_finish (G_FILE_ENUMERATOR (object), res, NULL);
 }
 
+static gboolean
+thaw_func (gpointer data)
+{
+  GtkFileSystemModel *model = data;
+
+  _gtk_file_system_model_thaw_updates (model);
+  model->dir_thaw_source = 0;
+
+  return FALSE;
+}
+
 static void
 gtk_file_system_model_got_files (GObject *object, GAsyncResult *res, gpointer data)
 {
@@ -859,26 +871,37 @@ gtk_file_system_model_got_files (GObject *object, GAsyncResult *res, gpointer da
 
   files = g_file_enumerator_next_files_finish (enumerator, res, &error);
 
-  _gtk_file_system_model_freeze_updates (model);
-  for (walk = files; walk; walk = walk->next)
+  if (files)
     {
-      const char *name;
-      GFileInfo *info;
-      GFile *file;
-      
-      info = walk->data;
-      name = g_file_info_get_name (info);
-      if (name == NULL)
+      if (model->dir_thaw_source == 0)
         {
-          /* Shouldn't happen, but the APIs allow it */
-          g_object_unref (info);
-          continue;
+          _gtk_file_system_model_freeze_updates (model);
+          model->dir_thaw_source = gdk_threads_add_timeout_full (IO_PRIORITY + 1,
+                                                                 50,
+                                                                 thaw_func,
+                                                                 model,
+                                                                 NULL);
+        }
+
+      for (walk = files; walk; walk = walk->next)
+        {
+          const char *name;
+          GFileInfo *info;
+          GFile *file;
+          
+          info = walk->data;
+          name = g_file_info_get_name (info);
+          if (name == NULL)
+            {
+              /* Shouldn't happen, but the APIs allow it */
+              g_object_unref (info);
+              continue;
+            }
+          file = g_file_get_child (model->dir, name);
+          gtk_file_system_model_add_node (model, file, info);
         }
-      file = g_file_get_child (model->dir, name);
-      gtk_file_system_model_add_node (model, file, info);
+      g_list_free (files);
     }
-  g_list_free (files);
-  _gtk_file_system_model_thaw_updates (model);
 
   if (files == NULL)
     {
@@ -891,11 +914,19 @@ gtk_file_system_model_got_files (GObject *object, GAsyncResult *res, gpointer da
         g_error_free (error);
       else
         g_signal_emit (model, file_system_model_signals[FINISHED_LOADING], 0, NULL);
+
+      if (model->dir_thaw_source != 0)
+        {
+          g_source_remove (model->dir_thaw_source);
+          model->dir_thaw_source = 0;
+          _gtk_file_system_model_thaw_updates (model);
+        }
+
       g_object_unref (model);
     }
   else
     g_file_enumerator_next_files_async (enumerator,
-                                        FILES_PER_QUERY,
+                                        g_file_is_native (model->dir) ? 50 * FILES_PER_QUERY : FILES_PER_QUERY,
                                         IO_PRIORITY,
                                         model->cancellable,
                                         gtk_file_system_model_got_files,
@@ -923,7 +954,7 @@ gtk_file_system_model_got_enumerator (GObject *dir, GAsyncResult *res, gpointer
   else
     {
       g_file_enumerator_next_files_async (enumerator,
-                                          FILES_PER_QUERY,
+                                          g_file_is_native (model->dir) ? 50 * FILES_PER_QUERY : FILES_PER_QUERY,
                                           IO_PRIORITY,
                                           model->cancellable,
                                           gtk_file_system_model_got_files,



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