Yay! I've done it: 1160 lines of bash script are now 1215 lines of perl, and:
'debtree aptitude': 1m2.832s -> 0m0.596s
The new release is available as version 0.9.9 from the
debtree web site and has been
uploaded for the archive as version 1.0.
This was the starting position, the run time for my complete test set:
real 22m33.583s
user 18m29.709s
sys 4m21.320s
I began with a pure language conversion from bash to perl, i.e. I kept
the call-outs to dctrl-tools. This allowed me to easily identify problems
in the language conversion by running my test suite, without having to worry
that a change might have been caused by getting different data.
The language conversion itself was fairly straightforward; most time was
spent on finding all the little errors made during the conversion.
This resulted in "only" a 10% speedup:
real 20m56.368s
user 18m3.996s
sys 2m46.986s
So bash itself isn't even horribly slower than perl, even with all the
recursion and starting of subshells for calls to grep, sed, etc.
Then I replaced the call-outs to dctrl-tools one by one, adding the
dependency on libapt-pkg-perl. And that resulted in the amazing:
real 0m21.350s
user 0m19.797s
sys 0m1.372s
So, from 22 minutes to 21 seconds for 22 graphs, including some pretty complex ones. Not bad.
I had to keep a call-out to dctrl-tools for build dependencies as it
turned out libapt-pkg-perl
does not expose architecture conditions.
The full conversion process can be seen in the source repository, which was recently moved from my $HOME on alioth to collab-maint.