{"thread":{"id":"10329","subject":"[PATCH] Speed up project listing for large working trees by limiting find depth","startedAt":"2007-10-16T23:02:01Z","lastAt":"2007-10-16T23:02:01Z","messageCount":1,"participants":["Luke Lu"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"56142","messageId":"1192575721-13666-1-git-send-email-git@vicaya.com","threadId":"10329","inReplyTo":null,"subject":"[PATCH] Speed up project listing for large working trees by limiting find depth","fromName":"Luke Lu","fromEmail":"git@vicaya.com","sentAt":"2007-10-16T23:02:01Z","receivedAt":"2007-10-16T23:02:01Z","isPatch":true,"sender":{"key":"git@vicaya.com","avatar":null},"body":"Forgot -s last time when resubmitting the patch.\n\nHere is a simple gitweb patch to speed up project listing on checked\nout repos with large trees. It was spending minutes in perl (5.8.8\nmacports).  Reduced to a fraction of a second after the patch.\n\nSigned-off-by: Luke Lu <git@vicaya.com>\n---\n gitweb/gitweb.perl |    4 ++++\n 1 files changed, 4 insertions(+), 0 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 3064298..a30eef9 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1509,16 +1509,20 @@ sub git_get_projects_list {\n \t\t# remove the trailing \"/\"\n \t\t$dir =~ s!/+$!!;\n \t\tmy $pfxlen = length(\"$dir\");\n+\t\tmy $pfxdepth = ($dir =~ tr!/!!);\n \n \t\tFile::Find::find({\n \t\t\tfollow_fast => 1, # follow symbolic links\n \t\t\tfollow_skip => 2, # ignore duplicates\n+\t\t\tno_chdir => 1, # don't chdir into every directory\n \t\t\tdangling_symlinks => 0, # ignore dangling symlinks, silently\n \t\t\twanted => sub {\n \t\t\t\t# skip project-list toplevel, if we get it.\n \t\t\t\treturn if (m!^[/.]$!);\n \t\t\t\t# only directories can be git repositories\n \t\t\t\treturn unless (-d $_);\n+\t\t\t\t# don't traverse too deep (Find is super slow on os x)\n+\t\t\t\treturn if tr!/!! - $pfxdepth > 2 && ($File::Find::prune = 1);\n \n \t\t\t\tmy $subdir = substr($File::Find::name, $pfxlen + 1);\n \t\t\t\t# we check related file in $projectroot\n-- \n1.5.3.4\n"}]}