guix-commits
[Top][All Lists]
Advanced

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

05/05: profiles: Compute manual database entries in parallel.


From: guix-commits
Subject: 05/05: profiles: Compute manual database entries in parallel.
Date: Tue, 31 Mar 2020 08:56:08 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit ef4b5f2fed3ca13a0e15a821ba7e561cd4395aa6
Author: Arne Babenhauserheide <address@hidden>
AuthorDate: Fri Jul 12 23:42:45 2019 +0200

    profiles: Compute manual database entries in parallel.
    
    This provides a 36% speedup on an SSD and 4 cores for the 1.5K man pages
    in the manual database derivation of:
    
      guix environment --ad-hoc jupyter python-ipython python-ipykernel
    
    * guix/profiles.scm (manual-database)[build]: Add 'print-string',
    'print', and 'compute-entry'.  Change 'compute-entries' to call
    'compute-entry' in 'n-par-map'.
    
    Co-authored-by: Ludovic Court├Ęs <address@hidden>
---
 guix/profiles.scm | 40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/guix/profiles.scm b/guix/profiles.scm
index 8aa76a3..47a7c92 100644
--- a/guix/profiles.scm
+++ b/guix/profiles.scm
@@ -1418,26 +1418,38 @@ the entries in MANIFEST."
         #~(begin
             (use-modules (guix man-db)
                          (guix build utils)
+                         (ice-9 threads)
                          (srfi srfi-1)
                          (srfi srfi-19))
 
+            (define (print-string msg)
+              (display msg)
+              (force-output))
+
+            (define-syntax-rule (print fmt args ...)
+              ;; Build up the string and display it at once.
+              (print-string (format #f fmt args ...)))
+
+            (define (compute-entry directory count total)
+              (print "\r[~3d/~3d] building list of man-db entries..."
+                     count total)
+              (let ((man (string-append directory "/share/man")))
+                (if (directory-exists? man)
+                    (mandb-entries man)
+                    '())))
+
             (define (compute-entries)
               ;; This is the most expensive part (I/O and CPU, due to
               ;; decompression), so report progress as we traverse INPUTS.
-              (let* ((inputs '#$(manifest-inputs manifest))
-                     (total  (length inputs)))
-                (append-map (lambda (directory count)
-                              (format #t "\r[~3d/~3d] building list of \
-man-db entries..."
-                                      count total)
-                              (force-output)
-                              (let ((man (string-append directory
-                                                        "/share/man")))
-                                (if (directory-exists? man)
-                                    (mandb-entries man)
-                                    '())))
-                            inputs
-                            (iota total 1))))
+              ;; Cap at 4 threads because we don't see any speedup beyond that
+              ;; on an SSD laptop.
+              (let* ((inputs  '#$(manifest-inputs manifest))
+                     (total   (length inputs))
+                     (threads (min (parallel-job-count) 4)))
+                (concatenate
+                 (n-par-map threads compute-entry inputs
+                            (iota total 1)
+                            (make-list total total)))))
 
             (define man-directory
               (string-append #$output "/share/man"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]