From 33ada9e9384390f1381f0b3563d5e1752e0ff3fa Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 10 Jul 2009 10:51:39 +0200 Subject: [PATCH] Bug 588273 - Make number of validated rows depend on time, not row count Previously, do_validate_rows() validated 300 rows per iteration. While this is usually not problematic, as the typical tree view contains less than 100 rows. 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 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index b4d4708761..0e52f92a95 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,9 +2043,8 @@ 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 - * sure we have some size. In practice, with a lot of static lists, this - * should get a good width. + /* we validate some rows initially just to make sure we have some size. + * In practice, with a lot of static lists, this should get a good width. */ do_validate_rows (tree_view, FALSE); gtk_tree_view_size_request_columns (tree_view); @@ -6118,6 +6117,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 +6136,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 +6216,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 +6245,7 @@ do_validate_rows (GtkTreeView *tree_view, gboolean queue_resize) } if (path) gtk_tree_path_free (path); + g_timer_destroy (timer); return retval; }