Re: Layer speedup



On Sun, Aug 22, 2010 at 11:12, Russell Strong <russell strong id au> wrote:
> Hi,
>
> The following patch replaces marker sorting ( by latitude ) with
> clutter's set_depth to achieve the same result.
>
> Using a modified animated-marker demo with 484 markers, this patch
> reduces CPU using on my laptop from 80% to 19%.
>
> There is still more that can be done, but that's now in clutter, which
> appears to be sorting a list every time a depth is changed.
>
> Any thoughts?

Nice! I've just applied it. I haven't measured the performance myself
but I believe your findings are correct and it's a nice simplification
as well. The only thing I have changed is that the code didn't take
into account the southern hemisphere where things are opposite - the
more you go to the south, the farther the markers should be. But this
bug was already present before your patch, I've just noticed it now.

Thanks!

Jiri

>
> Russell
>
>
>
> >From 332efb3705e01eb16c0eb1df8b038006f0c32638 Mon Sep 17 00:00:00 2001
> From: Russell Strong <russell strong id au>
> Date: Sun, 22 Aug 2010 18:40:32 +1000
> Subject: [PATCH] Speed up sorting of markers in the layer by using
> clutter's depth
>  instead of doing it ourselves.
>
> ---
>  champlain/champlain-layer.c |   40
> +++++++---------------------------------
>  1 files changed, 7 insertions(+), 33 deletions(-)
>
> diff --git a/champlain/champlain-layer.c b/champlain/champlain-layer.c
> index 2ef5c21..3229756 100644
> --- a/champlain/champlain-layer.c
> +++ b/champlain/champlain-layer.c
> @@ -117,43 +117,17 @@ champlain_layer_init (ChamplainLayer *self)
>  }
>
>
> -/* This callback serves to keep the markers ordered by their latitude.
> +/* This serves to keep the markers ordered by their latitude.
>  * Markers that are up north on the map should be lowered in the list
> so that
>  * they are drawn the first. This is to make the illusion of a semi-3d
> plane
>  * where the most north you are, the farther you are.
>  */
>  static void
> -reorder_marker (ClutterGroup *layer,
> -    ChamplainBaseMarker *marker)
> +set_marker_depth(GObject *marker)
>  {
> -  guint i;
> -  gdouble y, tmp_y, low_y;
> -  ChamplainBaseMarker *lowest = NULL;
> -
> -  g_object_get (G_OBJECT (marker), "latitude", &y, NULL);
> -  y = 90 - y;
> -  low_y = G_MAXDOUBLE;
> -
> -  for (i = 0; i < clutter_group_get_n_children (layer); i++)
> -    {
> -      ChamplainBaseMarker *prev_marker = CHAMPLAIN_BASE_MARKER
> (clutter_group_get_nth_child (layer, i));
> -
> -      if (prev_marker == (ChamplainBaseMarker *) marker)
> -        continue;
> -
> -      g_object_get (G_OBJECT (prev_marker), "latitude", &tmp_y, NULL);
> -      tmp_y = 90 - tmp_y;
> -
> -      if (y < tmp_y && tmp_y < low_y)
> -        {
> -          lowest = prev_marker;
> -          low_y = tmp_y;
> -        }
> -    }
> -
> -  if (lowest)
> -    clutter_container_lower_child (CLUTTER_CONTAINER (layer),
> -        CLUTTER_ACTOR (marker), CLUTTER_ACTOR (lowest));
> +  gdouble lat;
> +  g_object_get (G_OBJECT (marker), "latitude", &lat, NULL);
> +  clutter_actor_set_depth(CLUTTER_ACTOR(marker), 90.0 - lat);
>  }
>
>
> @@ -162,7 +136,7 @@ marker_position_notify (GObject *gobject,
>     G_GNUC_UNUSED GParamSpec *pspec,
>     gpointer user_data)
>  {
> -  reorder_marker (CLUTTER_GROUP (user_data), CHAMPLAIN_BASE_MARKER
> (gobject));
> +  set_marker_depth(gobject);
>  }
>
>
> @@ -173,7 +147,7 @@ layer_add_cb (ClutterGroup *layer,
>  {
>   ChamplainBaseMarker *marker = CHAMPLAIN_BASE_MARKER (actor);
>
> -  reorder_marker (layer, marker);
> +  set_marker_depth(G_OBJECT(actor));
>
>   g_signal_connect (G_OBJECT (marker), "notify::latitude",
>       G_CALLBACK (marker_position_notify), layer);
> --
> 1.7.2.1
>
>
>
> _______________________________________________
> libchamplain-list mailing list
> libchamplain-list gnome org
> http://mail.gnome.org/mailman/listinfo/libchamplain-list
>


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