possible optimization



I just realised that when calculating the "size" calculation for folders
(the number of items in the folder) we're currently getting all
information from the files in that folder (i.e. a stat call per file)
when we only really need the filenames.

The two attached patches avoids this, and testing with strace shows that
before applying we stat each file in a subdirectory of the displayed
file, whereas after we only do a readdir of each subdirectory. Of
course, this is only done if the size is shown in the view (optional in
icon view, always in list view).

Unfortunately the gnome-vfs patch adds a piece of API. Should we try to
get this into gnome 2.14? Opinions?

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a benighted hunchbacked jungle king from a doomed world. She's a 
beautiful streetsmart research scientist descended from a line of powerful 
witches. They fight crime! 
Index: doc/tmpl/gnome-vfs-file-info.sgml
===================================================================
RCS file: /cvs/gnome/gnome-vfs/doc/tmpl/gnome-vfs-file-info.sgml,v
retrieving revision 1.10
diff -u -p -r1.10 gnome-vfs-file-info.sgml
--- doc/tmpl/gnome-vfs-file-info.sgml	29 Nov 2005 16:35:02 -0000	1.10
+++ doc/tmpl/gnome-vfs-file-info.sgml	24 Feb 2006 09:19:02 -0000
@@ -99,6 +99,7 @@ stores information about files, GnomeVFS
 @GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE: 
 @GNOME_VFS_FILE_INFO_FOLLOW_LINKS: 
 @GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS: 
+ GNOME_VFS_FILE_INFO_NAME_ONLY: 
 
 <!-- ##### ENUM GnomeVFSSetFileInfoMask ##### -->
 <para>
Index: libgnomevfs/gnome-vfs-file-info.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-file-info.h,v
retrieving revision 1.34
diff -u -p -r1.34 gnome-vfs-file-info.h
--- libgnomevfs/gnome-vfs-file-info.h	19 Dec 2005 18:22:05 -0000	1.34
+++ libgnomevfs/gnome-vfs-file-info.h	24 Feb 2006 09:19:02 -0000
@@ -287,6 +287,9 @@ typedef struct {
  * to what would return access(2) on a local file system (ie is the 
  * file readable, writable and/or executable). Can be really slow on 
  * remote file systems
+ * @GNOME_VFS_FILE_INFO_ONLY_NAME: When reading a directory, only
+ * get the filename (if doing so is faster). Useful to e.g. count
+ * the number of files.
  *
  * Packed boolean bitfield representing options that can
  * be passed into a gnome_vfs_get_file_info() call (or other
@@ -300,7 +303,8 @@ typedef enum {
 	GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE = 1 << 1,
 	GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE = 1 << 2,
 	GNOME_VFS_FILE_INFO_FOLLOW_LINKS = 1 << 3,
-	GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS = 1 << 4
+	GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS = 1 << 4,
+	GNOME_VFS_FILE_INFO_NAME_ONLY = 1 << 5
 } GnomeVFSFileInfoOptions;
 
 /**
Index: modules/file-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/file-method.c,v
retrieving revision 1.152
diff -u -p -r1.152 file-method.c
--- modules/file-method.c	10 Jan 2006 15:06:45 -0000	1.152
+++ modules/file-method.c	24 Feb 2006 09:19:03 -0000
@@ -1001,6 +1001,10 @@ do_read_directory (GnomeVFSMethod *metho
 #endif
 	full_name = handle->name_buffer;
 
+	if (handle->options & GNOME_VFS_FILE_INFO_NAME_ONLY) {
+		return GNOME_VFS_OK;
+	}
+		
 	if (get_stat_info (file_info, full_name, handle->options, &statbuf) != GNOME_VFS_OK) {
 		/* Return OK - this should not terminate the directory iteration
 		 * and we will know from the valid_fields that we don't have the
Index: libnautilus-private/nautilus-directory-async.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-async.c,v
retrieving revision 1.218
diff -u -p -r1.218 nautilus-directory-async.c
--- libnautilus-private/nautilus-directory-async.c	12 Dec 2005 16:59:10 -0000	1.218
+++ libnautilus-private/nautilus-directory-async.c	24 Feb 2006 09:19:58 -0000
@@ -2216,7 +2216,7 @@ directory_count_start (NautilusDirectory
 	gnome_vfs_async_load_directory
 		(&directory->details->count_in_progress,
 		 uri,
-		 GNOME_VFS_FILE_INFO_DEFAULT,
+		 GNOME_VFS_FILE_INFO_NAME_ONLY,
 		 G_MAXINT,
 		 GNOME_VFS_PRIORITY_DEFAULT,
 		 directory_count_callback,


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