Skip to content
Snippets Groups Projects
Commit 9775412e authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

packages: Cache the result of 'package->bag'.

This reduces the wall-clock time of

  guix environment gnutls --pure -E true

by ~25%.

* guix/packages.scm (%bag-cache): New variable.
(package->bag): Use 'cached' to cache things to %BAG-CACHE.
parent 198d84b7
No related branches found
No related tags found
No related merge requests found
...@@ -798,41 +798,50 @@ (define derivation ...@@ -798,41 +798,50 @@ (define derivation
(package package) (package package)
(input x))))))) (input x)))))))
(define %bag-cache
;; 'eq?' cache mapping packages to system+target+graft?-dependent bags.
;; It significantly speeds things up when doing repeated calls to
;; 'package->bag' as is the case when building a profile.
(make-weak-key-hash-table 200))
(define* (package->bag package #:optional (define* (package->bag package #:optional
(system (%current-system)) (system (%current-system))
(target (%current-target-system)) (target (%current-target-system))
#:key (graft? (%graft?))) #:key (graft? (%graft?)))
"Compile PACKAGE into a bag for SYSTEM, possibly cross-compiled to TARGET, "Compile PACKAGE into a bag for SYSTEM, possibly cross-compiled to TARGET,
and return it." and return it."
;; Bind %CURRENT-SYSTEM and %CURRENT-TARGET-SYSTEM so that thunked field (cached (=> %bag-cache)
;; values can refer to it. package (list system target graft?)
(parameterize ((%current-system system) ;; Bind %CURRENT-SYSTEM and %CURRENT-TARGET-SYSTEM so that thunked
(%current-target-system target)) ;; field values can refer to it.
(match (if graft? (parameterize ((%current-system system)
(or (package-replacement package) package) (%current-target-system target))
package) (match (if graft?
(($ <package> name version source build-system (or (package-replacement package) package)
args inputs propagated-inputs native-inputs self-native-input? package)
outputs) (($ <package> name version source build-system
(or (make-bag build-system (string-append name "-" version) args inputs propagated-inputs native-inputs
#:system system self-native-input? outputs)
#:target target (or (make-bag build-system (string-append name "-" version)
#:source source #:system system
#:inputs (append (inputs) #:target target
(propagated-inputs)) #:source source
#:outputs outputs #:inputs (append (inputs)
#:native-inputs `(,@(if (and target self-native-input?) (propagated-inputs))
`(("self" ,package)) #:outputs outputs
'()) #:native-inputs `(,@(if (and target
,@(native-inputs)) self-native-input?)
#:arguments (args)) `(("self" ,package))
(raise (if target '())
(condition ,@(native-inputs))
(&package-cross-build-system-error #:arguments (args))
(package package))) (raise (if target
(condition (condition
(&package-error (&package-cross-build-system-error
(package package)))))))))) (package package)))
(condition
(&package-error
(package package)))))))))))
(define (input-graft store system) (define (input-graft store system)
"Return a procedure that, given a package with a graft, returns a graft, and "Return a procedure that, given a package with a graft, returns a graft, and
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment