[gtk+/filesystemmodel] Make number of validated rows depend on time, not on number of rows



commit 99ae34dbb4b25ca48721e2231896d80a1f6d344a
Author: Benjamin Otte <otte gnome org>
Date:   Fri Jul 10 10:51:39 2009 +0200

    Make number of validated rows depend on time, not on number of rows
    
    Previously, do_validate_rows() validated 300 rows per iteration. While
    this is usually not problematic, tree views with a lot of columns or
    complex cell renderers could take inacceptably long, like:
    - Epiphany's location bar entry completion has multiline and marked up
      text in every cell. Validating a single row took ~1.5ms here.
    - In the list view in Nautilus, When enabling all columns, validating a
      single row would take ~3ms.
    With 300 rows per iteration, that made those examples take 500ms/1s in a
    signle main loop callback, and this obviously caused responsiveness
    problems.
    
    Now the code uses a timer and limits the time for validating rows to
    30ms. This can cause less lines to be invalidated per call, so the
    function might be called more often, but generally results in more
    responsive applications.

 gtk/gtktreeview.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index b4d4708..6ad1f89 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -48,7 +48,7 @@
 
 #define GTK_TREE_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
 #define GTK_TREE_VIEW_PRIORITY_SCROLL_SYNC (GTK_TREE_VIEW_PRIORITY_VALIDATE + 2)
-#define GTK_TREE_VIEW_NUM_ROWS_PER_IDLE 500
+#define GTK_TREE_VIEW_TIME_MS_PER_IDLE 30
 #define SCROLL_EDGE_SIZE 15
 #define EXPANDER_EXTRA_PADDING 4
 #define GTK_TREE_VIEW_SEARCH_DIALOG_TIMEOUT 5000
@@ -2043,7 +2043,7 @@ gtk_tree_view_size_request (GtkWidget      *widget,
   GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
   GList *tmp_list;
 
-  /* we validate GTK_TREE_VIEW_NUM_ROWS_PER_IDLE rows initially just to make
+  /* we validate GTK_TREE_VIEW_TIME_MS_PER_IDLE rows initially just to make
    * sure we have some size. In practice, with a lot of static lists, this
    * should get a good width.
    */
@@ -6118,6 +6118,7 @@ do_validate_rows (GtkTreeView *tree_view, gboolean queue_resize)
   gint retval = TRUE;
   GtkTreePath *path = NULL;
   GtkTreeIter iter;
+  GTimer *timer;
   gint i = 0;
 
   gint prev_height = -1;
@@ -6136,6 +6137,9 @@ do_validate_rows (GtkTreeView *tree_view, gboolean queue_resize)
       return FALSE;
     }
 
+  timer = g_timer_new ();
+  g_timer_start (timer);
+
   do
     {
       if (! GTK_RBNODE_FLAG_SET (tree_view->priv->tree->root, GTK_RBNODE_DESCENDANTS_INVALID))
@@ -6213,7 +6217,7 @@ do_validate_rows (GtkTreeView *tree_view, gboolean queue_resize)
 
       i++;
     }
-  while (i < GTK_TREE_VIEW_NUM_ROWS_PER_IDLE);
+  while (g_timer_elapsed (timer, NULL) < GTK_TREE_VIEW_TIME_MS_PER_IDLE / 1000.);
 
   if (!tree_view->priv->fixed_height_check)
    {
@@ -6242,6 +6246,7 @@ do_validate_rows (GtkTreeView *tree_view, gboolean queue_resize)
     }
 
   if (path) gtk_tree_path_free (path);
+  g_timer_destroy (timer);
 
   return retval;
 }



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