GNOME Bugzilla – Bug 765640
pixelcache: reuse existing timeout source when possible
Last modified: 2016-04-27 10:27:13 UTC
This cuts some time out of all pixelcache backed widgets (TextView, TreeView, Viewport, etc) during scrolling since we can re-use the previous source.
Created attachment 326810 [details] [review] pixelcache: reuse existing timeout source when possible First off, this might seem like a layer violation simply because we know that it is a timeout source and that the timeout source uses the ready time to fire. But that couldn't really change without a break in GLib, so it seems perfectly fine to rely on it. This avoids the g_source_remove(), g_source_destroy(), g_timer_source_new(), and g_source_set_name_by_id() in the common case. Instead, we reuse our previous source and update the ready time to our new deadline. We lose the coalescing with g_timeout_add_seconds(), but that is not going to help in the common case anyway (unless you have three hands and can scroll multiple pixelcached backed widgets at once).
Review of attachment 326810 [details] [review]: ::: gtk/gtkpixelcache.c @@ +449,2 @@ + deadline = g_get_monotonic_time () + (BLOW_CACHE_TIMEOUT_SEC * G_USEC_PER_SEC); + source = g_main_context_find_source_by_id (NULL, cache->timeout_tag); if you go to this length, why not go all the way: keep the source pointer instead of the tag, and avoid the find-by-id ?
Created attachment 326823 [details] [review] pixelcache: reuse existing timeout source when possible This avoids the g_source_remove(), g_source_destroy(), g_timer_source_new(), and g_source_set_name_by_id() in the common case. Instead, we reuse our previous source and update the ready time to our new deadline. We lose the coalescing with g_timeout_add_seconds(), but that is not going to help in the common case anyway (unless you have three hands and can scroll multiple pixelcached backed widgets at once).
I was trying to be a little bit too minimal in the patch! This caches the GSource instead as suggested. While I was there, I cleaned up a couple other open coded pointer check/frees.
Attachment 326823 [details] pushed as 0763a02 - pixelcache: reuse existing timeout source when possible