From 4a0f02d061d551fbf3275ca4a82f0cf94f16eee5 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 5 Oct 2021 13:12:28 +0100 Subject: [PATCH] stdlib/fedora.gl: Try to cache dependencies For the large number of OCaml packages (~ 200) it takes a very long time to recompute the list of dependencies. The real reason for this is that we calculate the bin2src hash table over and over again for each dependency. Each time it takes about 6 seconds. Try one approach to caching this. This does improve performance quite a lot, at the minor annoyance of leaving ".depcache" files in the Fedora directory. A future approach might consider allowing bin2src to be created once when goals starts up and then making it available to all shell script snippets. I'm not sure how to implement that. Another possible approach in future would be to internalize the (key, value) cache implied here. This would let us cache the result of earlier runs so no recomputation would be needed. --- stdlib/fedora.gl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stdlib/fedora.gl b/stdlib/fedora.gl index bbc80d9..cb518bc 100644 --- a/stdlib/fedora.gl +++ b/stdlib/fedora.gl @@ -145,9 +145,15 @@ pure function fedora-source-dependencies (pkg) returning strings = @{ # list of binary packages they build, so work this out in advance. declare -A bin2src for p in %fedora-source-packages; do - for b in $(rpmspec -q --provides %fedora-dir/$p/%fedora-branch/$p.spec 2>/dev/null | awk '{print $1}'); do - bin2src[$b]=$p - done + p_specfile=%fedora-dir/$p/%fedora-branch/$p.spec + p_depcache=%fedora-dir/$p/%fedora-branch/.depcache + if ! test -f $p_depcache || test $p_specfile -nt $p_depcache; then + rm -f $p_depcache + for b in $(rpmspec -q --provides $p_specfile 2>/dev/null | awk '{print $1}'); do + echo "bin2src['$b']='$p'" >> $p_depcache + done + fi + source $p_depcache done for b in $(rpmspec -q --buildrequires $specfile 2>/dev/null | -- 1.8.3.1