From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: dired and ls (was: Human-readable file sorting) Date: Sat, 20 Feb 2016 11:57:40 +0200 Message-ID: <83k2lzpuuj.fsf@gnu.org> References: <87povs41xg.fsf@gnus.org> <87bn7c3yms.fsf@gnus.org> <87mvqvewk6.fsf_-_@gnus.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1455962287 12199 80.91.229.3 (20 Feb 2016 09:58:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 20 Feb 2016 09:58:07 +0000 (UTC) Cc: emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Feb 20 10:58:06 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aX4Ig-00088H-90 for ged-emacs-devel@m.gmane.org; Sat, 20 Feb 2016 10:58:06 +0100 Original-Received: from localhost ([::1]:59666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX4If-0003Hq-HP for ged-emacs-devel@m.gmane.org; Sat, 20 Feb 2016 04:58:05 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX4Ic-0003HK-4P for emacs-devel@gnu.org; Sat, 20 Feb 2016 04:58:03 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aX4IX-0001IV-4p for emacs-devel@gnu.org; Sat, 20 Feb 2016 04:58:02 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:58011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aX4IX-0001IL-1t; Sat, 20 Feb 2016 04:57:57 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:1201 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1aX4IV-0001x8-Rs; Sat, 20 Feb 2016 04:57:56 -0500 In-reply-to: <87mvqvewk6.fsf_-_@gnus.org> (message from Lars Ingebrigtsen on Sat, 20 Feb 2016 17:16:09 +1100) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:200292 Archived-At: > From: Lars Ingebrigtsen > Date: Sat, 20 Feb 2016 17:16:09 +1100 > > This all reminds me of something I forgot to prattle on about in that > dired bug report: ls-lisp.el. > > dired (on Unixey systems) uses "ls" to get the contents of directories, > and then parses the results. And generates a buffer. Not all systems > have "ls", so in that case it uses ls-lisp.el, which just calls > directory-files and then file-attributes in a loop. > > I think this is rather suboptimal for many reasons: > > 1) dired look unnecessarily different on different systems > > 2) the customisability is limited -- both the look of the buffers and > the sorting is limited by what the native "ls" returns > > 3) Reasons! So many reasons! > > I've asked "but why" before, but the only response I can remember is "ls > is faster". There's another reason: ls-lisp implements only a subset of options supported by 'ls' the program. > Which may be true! (I may be misremembering this being the > only answer.) Because `directory-files' uses opendir/readdir first to > get the file names, and then we have to stat each and every file just to > find out whether they're files or directories. > > If we instead had `directory-files-with-attributes' in C, we could just > do what "ls" does, which is... opening the directory, reading it, and > then statting all the files. ls-lisp already uses directory-files-with-attributes. > So it should be just as fast? I think? You should measure it, instead of trying to reason about that. IME, reasoning about relative timings of programs is never a good idea, because measurements always produce surprising results. One reason why ls-lisp might be slower is that it performs quite a bit of processing after reading the directory, and that processing is faster in C than in Lisp. But it could be faster in insignificant ways.