[sysprof/newui: 17/24] Apply yet another workaround for GTK+ performance issues.



commit d280dcf1e1deec40db60d2e86180b276f5a97f6b
Author: SÃren Sandmann Pedersen <sandmann daimi au dk>
Date:   Wed Nov 10 04:42:59 2010 -0500

    Apply yet another workaround for GTK+ performance issues.
    
    Sorting ends up emitting rows_reordered a lot, which requires building
    a bunch of GtkTreePaths, which is O(n^2) in the number of indices.
    
    By temporarily unsetting the model, we can avoid emitting those
    signals. To avoid an ugly flash, we also temporarily disable updating
    the tree view window.
    
    See https://bugzilla.gnome.org/show_bug.cgi?id=634491

 treeviewutils.c |   28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/treeviewutils.c b/treeviewutils.c
index af82da8..8c655af 100644
--- a/treeviewutils.c
+++ b/treeviewutils.c
@@ -88,6 +88,7 @@ tree_view_set_sort_column (GtkTreeView *view,
     GtkTreeSortable *sortable;
     GtkTreeViewColumn *column = find_column_by_model_column (view, model_column);
     SortInfo *info = get_sort_info (column);
+    GdkWindow *window;
     
     /* For each column in the view, unset the sort indicator */
     columns = gtk_tree_view_get_columns (view);
@@ -98,16 +99,35 @@ tree_view_set_sort_column (GtkTreeView *view,
 	gtk_tree_view_column_set_sort_indicator (col, FALSE);
     }
     
-    /* Set the sort indicator for this column */
-    gtk_tree_view_column_set_sort_indicator (column, TRUE);
-    gtk_tree_view_column_set_sort_order (column, sort_type);
-    
     /* And sort the column */
     sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (view));
+
+    /* Sorting ends up emitting rows_reordered a lot, which requires building
+     * a bunch of GtkTreePaths, which is O(n^2) in the number of indices.
+     *
+     * By temporarily unsetting the model, we can avoid emitting those
+     * signals. To avoid an ugly flash, we also temporarily disable updating
+     * the tree view window.
+     *
+     * See https://bugzilla.gnome.org/show_bug.cgi?id=634491
+     */
+    gdk_window_freeze_updates (gtk_widget_get_window (GTK_WIDGET (view)));
+
+    g_object_ref (sortable);
+    gtk_tree_view_set_model (view, NULL);
     
     gtk_tree_sortable_set_sort_column_id (sortable,
 					  info->model_column,
 					  sort_type);
+
+    gtk_tree_view_set_model (view, GTK_TREE_MODEL (sortable));
+    g_object_unref (GTK_TREE_MODEL (sortable));
+
+    /* Set the sort indicator for this column */
+    gtk_tree_view_column_set_sort_indicator (column, TRUE);
+    gtk_tree_view_column_set_sort_order (column, sort_type);
+
+    gdk_window_thaw_updates (gtk_widget_get_window (GTK_WIDGET (view)));
 }
 
 static void



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