From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: Optimizing union.scm Date: Tue, 25 Mar 2014 23:58:32 +0100 Message-ID: <87y4zx3mxz.fsf@gnu.org> References: <871tz8oldk.fsf@netris.org> <874n2oubuq.fsf@gnu.org> <8761n4mzvu.fsf@yeeloong.lan> <87siq8r77u.fsf@gnu.org> <87r45sl074.fsf_-_@yeeloong.lan> <87ha6nzp58.fsf@gnu.org> <87txamkbde.fsf@yeeloong.lan> <87bnwugptc.fsf@gnu.org> <87ob0tkj1p.fsf@yeeloong.lan> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WSaIt-0008Bc-GO for guix-devel@gnu.org; Tue, 25 Mar 2014 18:58:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WSaIl-00061y-9B for guix-devel@gnu.org; Tue, 25 Mar 2014 18:58:43 -0400 Received: from hera.aquilenet.fr ([2a01:474::1]:47865) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WSaIk-00061G-Qq for guix-devel@gnu.org; Tue, 25 Mar 2014 18:58:35 -0400 In-Reply-To: <87ob0tkj1p.fsf@yeeloong.lan> (Mark H. Weaver's message of "Tue, 25 Mar 2014 18:30:42 -0400") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Mark H Weaver Cc: guix-devel@gnu.org Mark H Weaver skribis: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> Mark H Weaver skribis: [...] >>> * I've not yet updated tests/union.scm, which tests internal procedures >>> in union.scm that no longer exist. >> >> Right, the =E2=80=98tree-union=E2=80=99 and =E2=80=98delete-duplicate-le= aves=E2=80=99 tests will have to >> be removed. >> >> However, could you add similar tests? They will have to use the real >> =E2=80=98union-build=E2=80=99, though. Maybe the =E2=80=98with-file-tre= e=E2=80=99 can be useful to >> write the tests. > > Could you help with this? I'm a bit overloaded right now. OK, I=E2=80=99ll add a few tests. >> Some stylistic comments: >> >>> (define (names-in-directory dirname) >>> (let ((dir (opendir dirname))) >>> (let loop ((filenames '())) >>> (match (readdir dir) >>> ((or "." "..") >>> (loop filenames)) >>> ((? eof-object?) >>> (closedir dir) >>> filenames) >>> (name >>> (loop (cons name filenames))))))) >> >> Rather use something like: >> >> (scandir directory (lambda (file) >> (not (member file '("." ".."))))) >> >> =E2=80=98scandir=E2=80=99 also has the advantage of being deterministic = (it sorts >> entries.) > > I looked at 'scandir', but it's very wasteful. For one thing, it > unconditionally calls 'lstat' on every directory entry, which entails > over ten thousand unnecessary 'lstat' system calls, a lot of unnecessary > I/O to read the inodes, the use of a vhash to keep track of where it has > been to detect cycles (since it's based on 'file-system-fold'), etc. Oh right, makes sense. Then just s/filenames/files/ and (sort files string>> (format log-port "`~a' ~~> `~a'~%" input output) >>> (symlink input output)) >>> >>> (define (union output inputs) >>> (match inputs >>> ((input) >>> ;; There's only one input, so just make a link. >>> (make-link input output)) >>> (_ >>> (receive (dirs files) (partition directory? inputs) >> >> Rather SRFI-11 let-values. > > Hmm. In simple cases like this, I find 'receive' much more attractive > than 'let-values', since the latter would involve triple-nested parens, > which is a bit much even for me. > > Can you explain why you prefer 'let-values' to 'receive' in this case? Because I=E2=80=99m used to it, but here it=E2=80=99s mostly for consistenc= y. > Also, how do you feel about 'call-with-values'? In an earlier draft of > this code, I used 'call-with-values' with 'match-lambda*' as the > consumer, which eliminated the need for the 'cond'. Would you prefer > that? Yeah I don=E2=80=99t feel too strongly, so whatever you find appropriate. = :-) Thanks! Ludo=E2=80=99.