GQuark in sfilog.c (Re: Optimizations)



On Tue, 3 Feb 2004, Stefan Westerfeld wrote:

> * No patches: performance of the unmodified build.
>
> stefan@luna1:~/src/beast-performance-eval/beast/tests$ perftest
> 0.980416 seconds for 10000 invocations => 10199.751787 invocations/second, 0.000098 sec per invocation

> * Patch #2: It's unnecessary to relookup the GQuark every time we do some
> logging output.
>
> Index: sfilog.c
> ===================================================================
> RCS file: /cvs/gnome/beast/sfi/sfilog.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 sfilog.c
> --- sfilog.c	7 Mar 2003 14:01:38 -0000	1.5
> +++ sfilog.c	2 Feb 2004 20:57:04 -0000
> @@ -26,19 +26,22 @@
>
>
>  /* --- functions --- */
> +
> +static GQuark sfi_log_key = 0;
> +

variables should go into an extra /* --- variables --- */ section,
take a look at e.g. sfiparams.c.

>  static inline const gchar*
>  sfi_log_pop_key (const gchar *fallback)
>  {
> -  const gchar *key = sfi_thread_get_data ("SFI-log-key");
> +  const gchar *key = sfi_thread_get_qdata (sfi_log_key);
>    if (key)
> -    sfi_thread_set_data ("SFI-log-key", NULL);
> +    sfi_thread_set_qdata (sfi_log_key, NULL);
>    return key ? key : fallback;
>  }
>
>  void
>  sfi_log_push_key (const gchar *static_key)
>  {
> -  sfi_thread_set_data ("SFI-log-key", (gchar*) static_key);
> +  sfi_thread_set_qdata (sfi_log_key, (gchar*) static_key);
>  }
>
>  static void
> @@ -206,6 +209,7 @@ _sfi_init_log (void)
>    sfi_mutex_init (&key_mutex);
>    sfi_log_reset_info ();
>    sfi_log_reset_debug ();
> +  sfi_log_key = g_quark_from_string ("SFI-log-key");
>  }
>
>  void

you should set the quark right after intializing the mutex (or
even before, wouldn't hurt) as future versions of sfi_log_reset_info/
sfi_log_reset_debug might make use of sfi_log_key.
also, i'm convetionally naming quarks quark_*, so please adjust
the variable name.

> stefan@luna1:~/src/beast-performance-eval/beast/tests$ perftest
> 0.915921 seconds for 10000 invocations => 10917.970867 invocations/second, 0.000092 sec per invocation
>

>
>    Cu... Stefan

---
ciaoTJ




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