diff options
author | Ludovic Courtès <ludo@gnu.org> | 2012-09-01 19:21:06 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2012-09-02 01:51:52 +0200 |
commit | aaa848f3afa81ec79579071f99d9bea5f8456f32 (patch) | |
tree | 77251d7791a99555a20ae3381ca522caafe633ce | |
parent | f39bd08ad223ae831312c9896e18f2f05ca5cbd0 (diff) | |
download | patches-aaa848f3afa81ec79579071f99d9bea5f8456f32.tar patches-aaa848f3afa81ec79579071f99d9bea5f8456f32.tar.gz |
Optimize `write-derivation' and `derivation-path->output-path'.
* guix/derivations.scm (write-derivation): Explicitly use
`simple-format'.
(derivation-path->output-path): Memoize.
-rw-r--r-- | guix/derivations.scm | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/guix/derivations.scm b/guix/derivations.scm index 213d9d5586..c9db580de6 100644 --- a/guix/derivations.scm +++ b/guix/derivations.scm @@ -200,6 +200,10 @@ available in STORE, recursively." "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 that form." + + ;; Make sure we're using the faster implementation. + (define format simple-format) + (define (list->string lst) (string-append "[" (string-join lst ",") "]")) @@ -269,12 +273,15 @@ that form." (string<? (car e1) (car e2)))))) (display ")" port)))) -(define* (derivation-path->output-path path #:optional (output "out")) - "Read the derivation from PATH (`/nix/store/xxx.drv'), and return the store +(define derivation-path->output-path + ;; This procedure is called frequently, so memoize it. + (memoize + (lambda* (path #:optional (output "out")) + "Read the derivation from PATH (`/nix/store/xxx.drv'), and return the store path of its output OUTPUT." - (let* ((drv (call-with-input-file path read-derivation)) - (outputs (derivation-outputs drv))) - (and=> (assoc-ref outputs output) derivation-output-path))) + (let* ((drv (call-with-input-file path read-derivation)) + (outputs (derivation-outputs drv))) + (and=> (assoc-ref outputs output) derivation-output-path))))) ;;; |