--- ../../gnome-menus-2.20.0/libmenu/entry-directories.c	2007-11-20 17:04:23.000000000 +0000
+++ entry-directories.c	2007-11-20 17:58:59.000000000 +0000
@@ -495,6 +495,19 @@
   g_free (uri);
 }
 
+typedef struct {
+    gchar *name;
+    ino_t  ino; 
+} FileEntry;
+
+static gint
+compare_by_inode (FileEntry *a, FileEntry *b)
+{
+    if (a->ino == b->ino)
+        return 0;
+    return a->ino > b->ino ? 1 : -1;
+}
+
 static gboolean
 cached_dir_load_entries_recursive (CachedDir  *dir,
                                    const char *dirname)
@@ -503,6 +516,8 @@
   struct dirent *dent;
   GString       *fullpath;
   gsize          fullpath_len;
+  GArray        *files;
+  int            i;
 
   g_assert (dir != NULL);
 
@@ -522,14 +537,11 @@
 
   cached_dir_ensure_monitor (dir, dirname);
 
-  fullpath = g_string_new (dirname);
-  if (fullpath->str[fullpath->len - 1] != G_DIR_SEPARATOR)
-    g_string_append_c (fullpath, G_DIR_SEPARATOR);
-
-  fullpath_len = fullpath->len;
-
+  files = g_array_new (FALSE, FALSE, sizeof (FileEntry));
   while ((dent = readdir (dp)) != NULL)
     {
+      FileEntry ent;
+
       /* ignore . and .. */
       if (dent->d_name[0] == '.' &&
           (dent->d_name[1] == '\0' ||
@@ -537,23 +549,41 @@
             dent->d_name[2] == '\0')))
         continue;
 
-      g_string_append (fullpath, dent->d_name);
+      ent.name = g_strdup (dent->d_name);
+      ent.ino = dent->d_ino;
+      g_array_append_val (files, ent);
+    }
+  closedir (dp);
 
-      if (g_str_has_suffix (dent->d_name, ".desktop") ||
-          g_str_has_suffix (dent->d_name, ".directory"))
+  // sort by inode to reduce disk I/O ...
+  g_array_sort (files, (GCompareFunc) compare_by_inode);
+
+  fullpath = g_string_new (dirname);
+  if (fullpath->str[fullpath->len - 1] != G_DIR_SEPARATOR)
+    g_string_append_c (fullpath, G_DIR_SEPARATOR);
+
+  fullpath_len = fullpath->len;
+
+  for (i = 0; i < files->len; i++) 
+    { 
+      char *name = g_array_index (files, FileEntry, i).name;
+      g_string_append (fullpath, name);
+
+      if (g_str_has_suffix (name, ".desktop") ||
+          g_str_has_suffix (name, ".directory"))
         {
-          cached_dir_add_entry (dir, dent->d_name, fullpath->str);
+          cached_dir_add_entry (dir, name, fullpath->str);
         }
       else /* Try recursing */
         {
-          cached_dir_add_subdir (dir, dent->d_name, fullpath->str);
+          cached_dir_add_subdir (dir, name, fullpath->str);
         }
 
       g_string_truncate (fullpath, fullpath_len);
+      g_free (name);
     }
 
-  closedir (dp);
-
+  g_array_free (files, TRUE);
   g_string_free (fullpath, TRUE);
 
   dir->have_read_entries = TRUE;
