grafts: Cache the derivation/graft mapping for the whole session.
authorLudovic Courtès <ludo@gnu.org>
Fri, 28 May 2021 15:32:58 +0000 (17:32 +0200)
committerLudovic Courtès <ludo@gnu.org>
Tue, 8 Jun 2021 07:25:50 +0000 (09:25 +0200)
commit0c109026093e6fa8730efe0d7454656275d6efe3
tree22658c44219f72ef303fbb1cb129005da3b04db1
parentfde3c349f511ac1237099511b5bdba5fbf541879
grafts: Cache the derivation/graft mapping for the whole session.

Partly fixes <https://bugs.gnu.org/41702>.
Reported by Lars-Dominik Braun <ldb@leibniz-psychology.org>.

Previously, 'graft-derivation' would start anew at every call.  When
creating a profile with lots of packages, it would potentially do the
same work multiple times.  The per-session cache addresses this.  It
increases the derivation-graft-cache hit rate from 77.9% to 80.1% on:

  GUIX_PROFILING="derivation-graft-cache" ./pre-inst-env \
    guix environment --ad-hoc libreoffice inkscape krita darktable -n

The effect is more visible on the pathological case below, where cache
hit rate goes from 75% to 87% and wall-clock time from 5.0s to 3.5s:

  GUIX_PROFILING="derivation-graft-cache" ./pre-inst-env \
    guix environment --ad-hoc r-learnr --search-paths

* guix/grafts.scm (%graft-cache): New variable.
(graft-derivation): Add calls to 'store-connection-cache' and
'set-store-connection-cache!'.
guix/grafts.scm