Control: tags -1 patch

On Thu, 01 Dec 2016 01:59:35 +0100 Simon Richter <s...@debian.org> wrote:
> Package: dpkg
> Version: 1.18.15
> Severity: minor
> 
> Hi,
> 
> when building the piglit package, the dpkg-shlibdeps invocations take
> upwards of 30 minutes (on an i7, building inside a tmpfs). Most of the
> time seems to be spent spawning several thousand instances of dpkg-query.
> 
> Is there a way to speed this up, e.g. with a cache?
> 
>    Simon
> 
> [...]
> 

Hi,

I have written the following patch that may be worth applying.  It
causes dpkg-shlibdeps to cache the result of get_control_path, which
results in a good speed improvement in my benchmark.

On the full piglit, it seems to reduce my runtime from about ~14m to ~2m

Thanks,
~Niels

From ff10b82e72b52c6af592f7dbda6d7964a155cb57 Mon Sep 17 00:00:00 2001
From: Niels Thykier <ni...@thykier.net>
Date: Sat, 1 Apr 2017 16:49:48 +0000
Subject: [PATCH 2/2] dpkg-shlibdeps: Cache get_control_path calls

It is basically a thin-wrapper around "dpkg-query --control-path" and
the repeated calls add up to quite a sum.

Results from a poor-mans performance test on ~90 ELF binaries from
piglit:

  * BEFORE:
    real    0m35.892s
    user    0m15.652s
    sys     0m18.584s

  * AFTER:
    real    0m10.884s
    user    0m7.316s
    sys     0m3.296s

Signed-off-by: Niels Thykier <ni...@thykier.net>
---
 scripts/dpkg-shlibdeps.pl | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/scripts/dpkg-shlibdeps.pl b/scripts/dpkg-shlibdeps.pl
index 76031b91f..656e9930c 100755
--- a/scripts/dpkg-shlibdeps.pl
+++ b/scripts/dpkg-shlibdeps.pl
@@ -739,6 +739,8 @@ sub extract_from_shlibs {
     return $dep;
 }
 
+my %symbols_file_cache;
+
 sub find_symbols_file {
     my ($pkg, $soname, $libfile) = @_;
     my @files;
@@ -754,7 +756,13 @@ sub find_symbols_file {
     } else {
 	push @files, "$Dpkg::CONFDIR/symbols/$pkg.symbols.$host_arch",
 	    "$Dpkg::CONFDIR/symbols/$pkg.symbols";
-	my $control_file = get_control_path($pkg, 'symbols');
+	my $control_file;
+	if (exists($symbols_file_cache{$pkg})) {
+	    $control_file = $symbols_file_cache{$pkg};
+	} else {
+	    $control_file = get_control_path($pkg, 'symbols');
+	    $symbols_file_cache{$pkg} = $control_file;
+	}
 	push @files, $control_file if defined $control_file;
     }
 
-- 
2.11.0

Reply via email to