~ruther/guix-local

d0840e4a2332de4f6eb4959836de569b413723c1 — Ludovic Courtès 13 years ago fce2394
derivations: Memoize `read-derivation'.

* guix/derivations.scm (read-derivation): Rename to...
  (%read-derivation): ... this.
  (read-derivation): New procedure.
  This reduces the execution of "guix-build gdb" from 2.5s to 1.7s.
1 files changed, 16 insertions(+), 3 deletions(-)

M guix/derivations.scm
M guix/derivations.scm => guix/derivations.scm +16 -3
@@ 155,9 155,8 @@ DRV and not already available in STORE, recursively."
                     inputs)
                (map derivation-input-sub-derivations inputs))))))

(define (read-derivation drv-port)
  "Read the derivation from DRV-PORT and return the corresponding
<derivation> object."
(define (%read-derivation drv-port)
  ;; Actually read derivation from DRV-PORT.

  (define comma (string->symbol ","))



@@ 222,6 221,20 @@ DRV and not already available in STORE, recursively."
       (loop (read drv-port)
             (cons (ununquote exp) result))))))

(define read-derivation
  (let ((cache (make-weak-value-hash-table 200)))
    (lambda (drv-port)
      "Read the derivation from DRV-PORT and return the corresponding
<derivation> object."
      ;; Memoize that operation because `%read-derivation' is quite expensive,
      ;; and because the same argument is read more than 15 times on average
      ;; during something like (package-derivation s gdb).
      (let ((file (and=> (port-filename drv-port) basename)))
        (or (and file (hash-ref cache file))
            (let ((drv (%read-derivation drv-port)))
              (hash-set! cache file drv)
              drv))))))

(define (write-derivation drv port)
  "Write the ATerm-like serialization of DRV to PORT.  See Section 2.4 of
Eelco Dolstra's PhD dissertation for an overview of a previous version of