From 44aaf9aa0a4d743564f23527f983f085a98b2f8d Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Sun, 17 Oct 2010 00:37:18 -0500 Subject: [PATCH] script/makepkg: add caching for port_all_bdeps and port_all_rdeps to avoid already-visited branches; fix port_all_bdeps to not ignore second-level bdeps As an optional test protocol, we are pleased to present an amusing fact: Computing the depgraph of an options-unchanged lang/php5-extensions, with and without caching: rdeps: With: 3.5 seconds Without: 22.7 seconds bdeps: With: 17.6 seconds Without: Gave up after 7 minutes --- script/makepkg | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/script/makepkg b/script/makepkg index af65988..77dea20 100755 --- a/script/makepkg +++ b/script/makepkg @@ -159,12 +159,33 @@ port_bdeps() { done } port_all_bdeps() { - # rdeps for rdeps are rdeps, rdeps for bdeps are bdeps; thus: - ( port_bdeps "${@}"; port_all_rdeps "${@}" ) | while read port - do - port_all_bdeps "${port}" - port_all_rdeps "${port}" - done | sort | uniq + # Clear cache if first value isn't '-r' + [ "${1}" = '-r' ] && shift || { : > "${_port_all_bdeps_cache}"; : > "${_port_all_rdeps_cache}"; } + # rdeps for rdeps are rdeps, bdeps for rdeps are bdeps, rdeps for bdeps are bdeps; thus: + ( + port_bdeps "${@}" | while read port + do + [ "${VERBOSE_CACHE}" ] && logf "**** bdep cache %s: '%s'\n" "$(grep -q "${port}" \ + "${_port_all_bdeps_cache}" && echo "hit" || echo "miss")" "${port}" >&2 + if ! grep -q "${port}" "${_port_all_bdeps_cache}" + then + echo "${port}" >> "${_port_all_bdeps_cache}" + echo "${port}" + port_all_bdeps -r "${port}" + port_all_rdeps -r "${port}" + fi + done + port_all_rdeps -r "${@}" | while read port + do + [ "${VERBOSE_CACHE}" ] && logf "**** bdep cache %s: '%s'\n" "$(grep -q "${port}" \ + "${_port_all_bdeps_cache}" && echo "hit" || echo "miss")" "${port}" >&2 + if ! grep -q "${port}" "${_port_all_bdeps_cache}" + then + echo "${port}" >> "${_port_all_bdeps_cache}" + port_all_bdeps -r "${port}" + fi + done + ) | sort | uniq } pkg_bdeps() { port2pkg $(port_all_bdeps "${@}") @@ -179,10 +200,18 @@ port_rdeps() { done } port_all_rdeps() { + # Clear cache if first value isn't '-r' + [ "${1}" = '-r' ] && shift || { : > "${_port_all_rdeps_cache}"; } port_rdeps "${@}" | while read port do - echo "${port}" - port_all_rdeps "${port}" + [ "${VERBOSE_CACHE}" ] && logf "**** rdep cache %s: '%s'\n" "$(grep -q "${port}" \ + "${_port_all_rdeps_cache}" && echo "hit" || echo "miss")" "${port}" >&2 + if ! grep -q "${port}" "${_port_all_rdeps_cache}" + then + echo "${port}" >> "${_port_all_rdeps_cache}" + echo "${port}" + port_all_rdeps -r "${port}" + fi done | sort | uniq } pkg_rdeps() { @@ -427,6 +456,10 @@ bdeps_dir="${pkg_dir}/bdeps" chroot_pkg_dir="${pkg_dir##${chroot_dir}}" chroot_bdeps_dir="${bdeps_dir##${chroot_dir}}" +# Cache files to speed up recursive bdep/rdep scanning +_port_all_bdeps_cache="${chroot_dir}/tmp/_port_all_bdeps_cache" +_port_all_rdeps_cache="${chroot_dir}/tmp/_port_all_rdeps_cache" + # Chroot environment chroot_env=" USER=root -- 2.42.0