[GNOME VFS] Re: mime info parsing patch ...

Seth Nickell <[email protected]> 09 Jul 2002 22:08:43 -0700
Newsgroups gmane.comp.gnome.vfs
Message-ID <1026277723.1521.7.camel@quixotic>
Wow, its hard for me to believe these changes have such a substantial
performance effect, but they look right, so please go ahead and commit
them to HEAD. I wouldn't spend too much more time on optimizing this
though, since we're probably going to be changing parsers in the
not-so-distant future when we get an agreement with other freedesktop
folk (actually, I would welcome your input into this process since a lot
of the discussion since you've worked a lot with the MIME parsing).

-Seth

On Thu, 2002-07-11 at 04:13, Michael Meeks wrote:
> Hi there,
> 
> 	This patch gets mime parsing down to ~33ms on my machine down from 51ms
> by doing some simple things, That doesn't sound much, but on my Ultra 2
> it takes ~ 380ms to parse, hopefully this will get it down to 250 or so.
> 
> 	May I commit ?
> 
> 	Regards,
> 
> 		Michael.
> 
> Index: ChangeLog
> ===================================================================
> RCS file: /cvs/gnome/gnome-vfs/ChangeLog,v
> retrieving revision 1.1334.2.12
> diff -u -p -u -r1.1334.2.12 ChangeLog
> --- ChangeLog	9 Jul 2002 13:40:49 -0000	1.1334.2.12
> +++ ChangeLog	11 Jul 2002 11:09:52 -0000
> @@ -1,4 +1,15 @@
> +2002-07-11  Michael Meeks  <[email protected]>
> +
> +	* libgnomevfs/gnome-vfs-mime-info.c
> +	(load_type_info_from): use g_string_truncate
> +	for a 20% speedup.
> +	(APPEND_CHAR): inline more for another 20%.
> +
> +	* test/test-mime.c (main): add --speedTest
> +	for mime info reloading.
> +
>  2002-07-05  Stephen Browne  <[email protected]>
> +
>  	* modules/cdemenu-desktop-method.c
>  	Patch from [email protected]
>  	modified the code so that the function create_cde_icon_name_cache
> Index: libgnomevfs/gnome-vfs-mime-info.c
> ===================================================================
> RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-mime-info.c,v
> retrieving revision 1.63.2.1
> diff -u -p -u -r1.63.2.1 gnome-vfs-mime-info.c
> --- libgnomevfs/gnome-vfs-mime-info.c	26 Jun 2002 02:33:32 -0000	1.63.2.1
> +++ libgnomevfs/gnome-vfs-mime-info.c	11 Jul 2002 11:09:53 -0000
> @@ -303,7 +303,17 @@ typedef enum {
>  	STATE_ON_VALUE
>  } ParserState;
>  
> -#define APPEND_CHAR(gstr,c) g_string_insert_c ((gstr), -1, (c))
> +/* #define APPEND_CHAR(gstr,c) g_string_insert_c ((gstr), -1, (c)) */
> +
> +#define APPEND_CHAR(gstr,c) \
> +	G_STMT_START {                                     \
> +		if (gstr->len + 1 < gstr->allocated_len) { \
> +			gstr->str [gstr->len++] = c;       \
> +			gstr->str [gstr->len] = '\0';      \
> +		} else {                                   \
> +			g_string_insert_c (gstr, -1, c);   \
> +		}                                          \
> +	} G_STMT_END
>  
>  typedef enum {
>  	FORMAT_MIME,
> @@ -352,7 +362,7 @@ load_type_info_from (const char *filenam
>  			if (c == '\n') {
>  				skip_line = FALSE;
>  				column = -1;
> -				g_string_assign (line, "");
> +				g_string_truncate (line, 0);
>  				key = lang = last_str_end = 0;
>  			}
>  			continue;
> @@ -374,7 +384,7 @@ load_type_info_from (const char *filenam
>  						 line->str + last_str_end);
>  				key = lang = 0;
>  			}
> -			g_string_assign (line, "");
> +			g_string_truncate (line, 0);
>  			last_str_end = 0;
>  			state = STATE_LOOKING_FOR_KEY;
>  			continue;
> @@ -478,7 +488,7 @@ load_type_info_from (const char *filenam
>  				    language_level (line->str + lang) < 0) {
>  					skip_line = TRUE;
>  					key = lang = last_str_end = 0;
> -					g_string_assign (line, "");
> +					g_string_truncate (line, 0);
>  					state = STATE_LOOKING_FOR_KEY;
>  				}
>  			} else {
> Index: test/test-mime.c
> ===================================================================
> RCS file: /cvs/gnome/gnome-vfs/test/test-mime.c,v
> retrieving revision 1.13
> diff -u -p -u -r1.13 test-mime.c
> --- test/test-mime.c	17 May 2002 11:00:18 -0000	1.13
> +++ test/test-mime.c	11 Jul 2002 11:09:53 -0000
> @@ -26,6 +26,7 @@
>  #include <libgnomevfs/gnome-vfs-init.h>
>  #include <libgnomevfs/gnome-vfs-mime-magic.h>
>  #include <libgnomevfs/gnome-vfs-mime-utils.h>
> +#include <libgnomevfs/gnome-vfs-mime-info.h>
>  #include <libgnomevfs/gnome-vfs-mime.h>
>  #include <libgnomevfs/gnome-vfs-utils.h>
>  
> @@ -66,16 +67,20 @@ main (int argc, char **argv)
>  	gboolean magic_only;
>  	gboolean suffix_only;
>  	gboolean dump_table;
> +	gboolean speed_test;
>  	const char *result;
>  	const char *table_path;
>  	char *uri_string;
>  	char *curdir;
>  	char *path;
>  	struct stat tmp;
> +	GTimer *timer;
> +	int i;
>  
>  	table_path = NULL;
>  	magic_only = FALSE;
>  	dump_table = FALSE;
> +	speed_test = FALSE;
>  	suffix_only = FALSE;
>  	
>  	if (!gnome_vfs_init ()) {
> @@ -98,6 +103,8 @@ main (int argc, char **argv)
>  			suffix_only = TRUE;
>  		} else if (strcmp (*argv, "--dumpTable") == 0) {
>  			dump_table = TRUE;
> +		} else if (strcmp (*argv, "--speedTest") == 0) {
> +			speed_test = TRUE;
>  		} else if (strcmp (*argv, "--loadTable") == 0) {
>  			++argv;
>  			if (!*argv) {
> @@ -121,6 +128,16 @@ main (int argc, char **argv)
>  
>  	if (dump_table) {
>  		gnome_vfs_mime_dump_magic_table ();
> +	}
> +
> +	if (speed_test) {
> +		timer = g_timer_new ();
> +		g_timer_start (timer);
> +		for (i = 0; i < 100; i++) {
> +			gnome_vfs_mime_info_reload ();
> +		}
> +		fprintf (stderr, "Mime reload took %g(ms)\n",
> +			 g_timer_elapsed (timer, NULL) * 10.0);
>  	}
>  
>  	for (; *argv != NULL; argv++) {
> -- 
>  [email protected]  <><, Pseudo Engineer, itinerant idiot
> 



_______________________________________________
gnome-vfs maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gnome-vfs