[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

up to 25% reduction in runtime of `dpkg -S'



I've been studying the implementation of `dpkg -S'.  I used gprof to
gather some hard information and discovered that a large proportion of
the runtime is spent in parsedb(), which is called twice, once to read
the status file and once to read the available file.

(There would appear to be situations in which it can be called more
often than that, which I don't fully understand yet, but I don't think 
they're immediately relevant.)

I have a modified dpkg in which `dpkg -S' does not parse the available
file.  I get a speed improvement of 25% when searching for a single
file and almost 20% when searching for all files.  Here are my
figures:

lyonesse$ for i in a b c d; do time dpkg -S /bin/ls; done >/dev/null

real    0m2.396s
user    0m1.740s
sys     0m0.650s

real    0m2.394s
user    0m1.730s
sys     0m0.670s

real    0m2.401s
user    0m1.760s
sys     0m0.640s

real    0m2.392s
user    0m1.780s
sys     0m0.610s
lyonesse$ for i in a b c d; do time main/dpkg -S /bin/ls; done >/dev/null

real    0m1.772s
user    0m1.130s
sys     0m0.640s

real    0m1.778s
user    0m1.210s
sys     0m0.570s

real    0m1.775s
user    0m1.220s
sys     0m0.560s

real    0m1.865s
user    0m1.130s
sys     0m0.660s
lyonesse$ 
lyonesse$ for i in a b c d; do time dpkg -S \*; done >/dev/null
real    0m3.235suser    0m2.280s
sys     0m0.950s

real    0m3.320s
user    0m2.320s
sys     0m0.970s

real    0m3.233s
user    0m2.220s
sys     0m1.020s

real    0m3.253s
user    0m2.360s
sys     0m0.890s
lyonesse$ for i in a b c d; do time main/dpkg -S \*; done >/dev/null

real    0m2.603s
user    0m1.930s
sys     0m0.670s

real    0m2.653s
user    0m1.800s
sys     0m0.810s

real    0m2.608s
user    0m1.770s
sys     0m0.840s

real    0m2.613s
user    0m1.700s
sys     0m0.920s

Below is the diff.  It's uuencoded to keep tabs safe.  It works by
adding an msdbrw_noavail flag which searchfiles() passes to
modstatdb_init() to request that the available file not be read.

If I have missed some crucial fact about the implementation that means 
that the `available' file must be parsed, then I offer my apologies in 
advance, and would point out that I haven't had any breakfast yet.

ttfn/rjk

begin 644 dpk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