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

Re: [Ext2-devel] Re: Debbugs: The Next Generation



On Sat, Aug 18, 2001 at 04:19:06AM -0500, Adam Heath wrote:
> 
> Actually, this patch will not help the following perl-snipet/pseudo code:
> 
> @list = sort readdir( DIR );
> foreach ( @list ) {
> 	stat;
> }

It won't help, but it won't hurt, either.  If you do this silly thing,
on average you will have to search 50% of the files in the directory
both before or after my patch.

> I feel the above code is probably quite common too.

I've checked, and du, find, and "ls -l" all do it "right".  That is,
they stat in readdir() order.  In the case of du and find, there's no
need to sort the results, so they don't.  In the case of ls, it does
sort the result for the user, but it does so *after* doing the stat.

The pseudo code which you've written is easy to do in perl, but in C,
it's actually much easier to do things the faster way.  (i.e., iterate
over the files as returned by readdir, and stat them as you go.)  

Given that this gives optimal results on most historical Unix systems
(i.e., BSD UFS/FFS, Solaris UFS, etc.), plus the fact that in C it's
easier to code things the optimal way, I wouldn't be too surprised if
most programs do things in readdir order.

(Of course as we all know, all the world runs Linux, so optmizations
which make programs go faster on other systems like Solaris aren't of
interest to most Linux programmers --- unfortunately.  :-/  )

							- Ted



Reply to: