On Wednesday 07 November 2007 17:11:38 Werner Hoch wrote:

> > > 2. Copying of my generated symbols is slow in gschem. If I place
> > > 100 symbols and create a copy, it currently takes quite long (about
> > > 20s).
> >
> > Hmm... is it any slower for the file-based symbols compared to the
> > command-based ones?
>
> Yes. I don't notice any delay when copying file-based symbols.
>
> > If so, that's bad and shouldn't be happening -- the symbol data's
> > supposed to be cached.
>
> gschem calls my script over and over again.

Try the attached patchset.  This will cache symbols until the cache is next 
invalidated (e.g. by explicit flushing, adding component sources, or clicking 
the "Refresh" button).

Performance seems to be better, although I haven't done any benchmarking.

Cheers,

                           Peter

-- 
Peter Brett

Electronic Systems Engineer
Integral Informatics Ltd
From 853e933b738ccc33e1348ef6f1604466a4a49220 Mon Sep 17 00:00:00 2001
From: Peter TB Brett <[EMAIL PROTECTED]>
Date: Wed, 28 Nov 2007 23:22:43 +0000
Subject: [PATCH] libgeda: Clean g_assert usage in s_clib.c

---
 libgeda/src/s_clib.c |   44 ++++++++++++++++++++++++++------------------
 1 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/libgeda/src/s_clib.c b/libgeda/src/s_clib.c
index 28e2878..bee7be8 100644
--- a/libgeda/src/s_clib.c
+++ b/libgeda/src/s_clib.c
@@ -387,7 +387,9 @@ static gchar *run_source_command (const gchar *command)
   gint exit_status;
   GError *e = NULL;
   gboolean success = FALSE;
-  
+
+  g_return_val_if_fail((command != NULL), NULL);
+
   g_spawn_command_line_sync (command,
                              &standard_output,
                              &standard_error,
@@ -512,8 +514,8 @@ static void refresh_directory (CLibSource *source)
   gboolean isfile;
   GError *e = NULL;
 
-  g_assert (source != NULL);
-  g_assert (source->type == CLIB_DIR);
+  g_return_if_fail (source != NULL);
+  g_return_if_fail (source->type == CLIB_DIR);
 
   /* Clear the current symbol list */
   g_list_foreach (source->symbols, (GFunc) free_symbol, NULL);
@@ -587,8 +589,8 @@ static void refresh_command (CLibSource *source)
   CLibSymbol *symbol;
   gchar *name;
 
-  g_assert (source != NULL);
-  g_assert (source->type == CLIB_CMD);
+  g_return_if_fail (source != NULL);
+  g_return_if_fail (source->type == CLIB_CMD);
 
   /* Clear the current symbol list */
   g_list_foreach (source->symbols, (GFunc) free_symbol, NULL);
@@ -647,8 +649,8 @@ static void refresh_scm (CLibSource *source)
   SCM symname;
   CLibSymbol *symbol;
 
-  g_assert (source != NULL);
-  g_assert (source->type == CLIB_SCM);
+  g_return_if_fail (source != NULL);
+  g_return_if_fail (source->type == CLIB_SCM);
 
   /* Clear the current symbol list */
   g_list_foreach (source->symbols, (GFunc) free_symbol, NULL);
@@ -720,7 +722,9 @@ void s_clib_refresh ()
 	refresh_scm (source);
 	break;
       default:
-	g_assert_not_reached();
+	g_critical("s_clib_refresh: source %p has bad source type %i\n",
+                   source, (gint) source->type);
+        break;
       }
   }
 }
@@ -991,8 +995,8 @@ static gchar *get_data_directory (const CLibSymbol *symbol)
   gchar *data = NULL;
   GError *e = NULL;
 
-  g_assert (symbol != NULL);
-  g_assert (symbol->source->type == CLIB_DIR);
+  g_return_val_if_fail ((symbol != NULL), NULL);
+  g_return_val_if_fail ((symbol->source->type == CLIB_DIR), NULL);
 
   filename = g_build_filename(symbol->source->directory, 
 			      symbol->name, NULL);
@@ -1024,8 +1028,8 @@ static gchar *get_data_command (const CLibSymbol *symbol)
   gchar *command;
   gchar *result;
 
-  g_assert (symbol != NULL);
-  g_assert (symbol->source->type == CLIB_CMD);
+  g_return_val_if_fail ((symbol != NULL), NULL);
+  g_return_val_if_fail ((symbol->source->type == CLIB_CMD), NULL);
   
   command = g_strdup_printf ("%s %s", symbol->source->get_cmd, 
                           symbol->name);
@@ -1051,8 +1055,8 @@ static gchar *get_data_scm (const CLibSymbol *symbol)
 {
   SCM symdata;
 
-  g_assert (symbol != NULL);
-  g_assert (symbol->source->type == CLIB_SCM);
+  g_return_val_if_fail ((symbol != NULL), NULL);
+  g_return_val_if_fail ((symbol->source->type == CLIB_SCM), NULL);
 
   symdata = scm_call_1 (symbol->source->get_fn, 
 			scm_from_locale_string (symbol->name));
@@ -1079,7 +1083,8 @@ static gchar *get_data_scm (const CLibSymbol *symbol)
  */
 gchar *s_clib_symbol_get_data (const CLibSymbol *symbol)
 {
-  g_assert (symbol != NULL);
+  g_return_val_if_fail ((symbol != NULL), NULL);
+  g_return_val_if_fail ((symbol->source != NULL), NULL);
 
   switch (symbol->source->type)
     {
@@ -1090,7 +1095,9 @@ gchar *s_clib_symbol_get_data (const CLibSymbol *symbol)
     case CLIB_SCM:
       return get_data_scm (symbol);
     default:
-      g_assert_not_reached();
+      g_critical("s_clib_symbol_get_data: source %p has bad source type %i\n",
+                 symbol->source, (gint) symbol->source->type);
+      return NULL;
     }
 }
 
@@ -1140,7 +1147,8 @@ GList *s_clib_search (const gchar *pattern, const CLibSearchMode mode)
       keytype = 's';
       break;
     default:
-      g_assert_not_reached();
+      g_critical ("s_clib_search: Bad search mode %i\n", mode);
+      return NULL;
     }
   key = g_strdup_printf("%c%s", keytype, pattern);
 
@@ -1307,7 +1315,7 @@ GList *s_toplevel_get_symbols (const TOPLEVEL *toplevel)
   CLibSymbol *sym = NULL;
   const GList *p_iter;
 
-  g_assert (toplevel != NULL);
+  g_return_val_if_fail ((toplevel != NULL), NULL);
 
   for ( p_iter = geda_list_get_glist( toplevel->pages );
         p_iter != NULL;
-- 
1.5.3.3

From 73edcd628ddf7b8ed63fb35cb7a0ff8b05b32d51 Mon Sep 17 00:00:00 2001
From: Peter TB Brett <[EMAIL PROTECTED]>
Date: Wed, 28 Nov 2007 23:22:52 +0000
Subject: [PATCH] clib: Cache symbol data between library refreshes

Adds a cache for symbol data, which is flushed whenever the available
component libraries are changed or rescanned.  This should speed up
large component copying operations.
---
 libgeda/include/prototype.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/libgeda/include/prototype.h b/libgeda/include/prototype.h
index 7f4665f..6e21ef1 100644
--- a/libgeda/include/prototype.h
+++ b/libgeda/include/prototype.h
@@ -488,6 +488,7 @@ const CLibSource *s_clib_symbol_get_source (const CLibSymbol *symbol);
 gchar *s_clib_symbol_get_data (const CLibSymbol *symbol);
 GList *s_clib_search (const gchar *pattern, const CLibSearchMode mode);
 void s_clib_flush_search_cache ();
+void s_clib_flush_symbol_cache ();
 const CLibSymbol *s_clib_get_symbol_by_name (const gchar *name);
 gchar *s_clib_symbol_get_data_by_name (const gchar *name);
 GList *s_toplevel_get_symbols (const TOPLEVEL *toplevel);
-- 
1.5.3.3

From cc16554014e48ef3b806118d834c47f97e6dff65 Mon Sep 17 00:00:00 2001
From: Peter TB Brett <[EMAIL PROTECTED]>
Date: Wed, 28 Nov 2007 23:22:49 +0000
Subject: [PATCH] clib: Clarify naming for search cache

---
 libgeda/include/prototype.h |    2 +-
 libgeda/src/s_clib.c        |   30 +++++++++++++++---------------
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libgeda/include/prototype.h b/libgeda/include/prototype.h
index ede03ef..7f4665f 100644
--- a/libgeda/include/prototype.h
+++ b/libgeda/include/prototype.h
@@ -487,7 +487,7 @@ gchar *s_clib_symbol_get_filename (const CLibSymbol *symbol);
 const CLibSource *s_clib_symbol_get_source (const CLibSymbol *symbol);
 gchar *s_clib_symbol_get_data (const CLibSymbol *symbol);
 GList *s_clib_search (const gchar *pattern, const CLibSearchMode mode);
-void s_clib_flush_cache ();
+void s_clib_flush_search_cache ();
 const CLibSymbol *s_clib_get_symbol_by_name (const gchar *name);
 gchar *s_clib_symbol_get_data_by_name (const gchar *name);
 GList *s_toplevel_get_symbols (const TOPLEVEL *toplevel);
diff --git a/libgeda/src/s_clib.c b/libgeda/src/s_clib.c
index bee7be8..aa1f336 100644
--- a/libgeda/src/s_clib.c
+++ b/libgeda/src/s_clib.c
@@ -205,7 +205,7 @@ struct _CLibSymbol {
 static GList *clib_sources = NULL;
 
 /*! Caches results of s_clib_search() */
-static GHashTable *clib_cache = NULL;
+static GHashTable *clib_search_cache = NULL;
 
 /* Local static functions
  * ======================
@@ -238,13 +238,13 @@ void s_clib_init ()
     s_clib_free ();
   }
 
-  if (clib_cache != NULL) {
-    s_clib_flush_cache();
+  if (clib_search_cache != NULL) {
+    s_clib_flush_search_cache();
   } else {
-    clib_cache = g_hash_table_new_full ((GHashFunc) g_str_hash,
-					(GEqualFunc)g_str_equal,
-					(GDestroyNotify) g_free, 
-					(GDestroyNotify) g_list_free);
+    clib_search_cache = g_hash_table_new_full ((GHashFunc) g_str_hash,
+                                               (GEqualFunc)g_str_equal,
+                                               (GDestroyNotify) g_free,
+                                               (GDestroyNotify) g_list_free);
   }
 }
 
@@ -571,7 +571,7 @@ static void refresh_directory (CLibSource *source)
   source->symbols = g_list_sort (source->symbols, 
 				 (GCompareFunc) compare_symbol_name);
 
-  s_clib_flush_cache();
+  s_clib_flush_search_cache();
 }
 
 /*! \brief Re-poll a library command for symbols.
@@ -633,7 +633,7 @@ static void refresh_command (CLibSource *source)
   source->symbols = g_list_sort (source->symbols, 
 				 (GCompareFunc) compare_symbol_name);
 
-  s_clib_flush_cache();
+  s_clib_flush_search_cache();
 }
 
 /*! \brief Re-poll a scheme procedure for symbols.
@@ -688,7 +688,7 @@ static void refresh_scm (CLibSource *source)
   source->symbols = g_list_sort (source->symbols, 
 				 (GCompareFunc) compare_symbol_name);
 
-  s_clib_flush_cache();
+  s_clib_flush_search_cache();
 }
 
 /*! \brief Rescan all available component libraries.
@@ -1153,7 +1153,7 @@ GList *s_clib_search (const gchar *pattern, const CLibSearchMode mode)
   key = g_strdup_printf("%c%s", keytype, pattern);
 
   /* Check to see if the query is already in the cache */
-  result = (GList *) g_hash_table_lookup (clib_cache, key);
+  result = (GList *) g_hash_table_lookup (clib_search_cache, key);
   if (result != NULL) {
     g_free (key);
     return g_list_copy (result);
@@ -1197,7 +1197,7 @@ GList *s_clib_search (const gchar *pattern, const CLibSearchMode mode)
     g_pattern_spec_free (globpattern);
   }
 
-  g_hash_table_insert (clib_cache, key, g_list_copy (result));
+  g_hash_table_insert (clib_search_cache, key, g_list_copy (result));
   /* __don't__ free key here, it's stored by the hash table! */
 
   return result;
@@ -1220,12 +1220,12 @@ static gboolean remove_entry(gpointer key, gpointer val, gpointer data)
  *  You shouldn't ever need to call this, as all functions which
  *  invalidate the cache are supposed to make sure it's flushed.
  */
-void s_clib_flush_cache ()
+void s_clib_flush_search_cache ()
 {
 #if GLIB_CHECK_VERSION(2,12,0)
-  g_hash_table_remove_all (clib_cache);  /* Introduced in glib 2.12 */
+  g_hash_table_remove_all (clib_search_cache);  /* Introduced in glib 2.12 */
 #else
-  g_hash_table_foreach_remove(clib_cache, remove_entry, NULL);
+  g_hash_table_foreach_remove(clib_search_cache, remove_entry, NULL);
 #endif
 }
 
-- 
1.5.3.3

Attachment: signature.asc
Description: This is a digitally signed message part.


_______________________________________________
geda-dev mailing list
[email protected]
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev

Reply via email to