Re: Optimize script for generating LinuxManBook.pdf

Alejandro Colomar
2023-11-24T11:46:39Z

[-- Attachment #1: Type: text/plain, Size: 1892 bytes --]

On Thu, Nov 23, 2023 at 11:12:45PM +0100, Alejandro Colomar wrote:
> > It looks fine, although you have to run the code in
> > "prepare_linux_man_book.pl" twice (to avoid using a temporary file).
>
> Yep. I was wondering if we could change something in the design of
> prepare_linux_man_book.pl so that it could be run once without needing
> a temporary file. Maybe if it could insert something in the pages that
> the latter troff(1) would process in one take, without having to put all
> the bookmarks at the start of the file. That would be an important
> simplification of the scripts, and probably also an optimization.

Hi Deri,

I have another optimization: split the sort. It reduces around 0.3 s.

diff --git a/scripts/LinuxManBook/prepare_linux_man_book.pl b/scripts/LinuxManBook/prepare_linux_man_book.pl
index 0a79df4e5..5a4aad429 100755
--- a/scripts/LinuxManBook/prepare_linux_man_book.pl
+++ b/scripts/LinuxManBook/prepare_linux_man_book.pl
@@ -88,7 +88,16 @@ sub BuildBook
{
print ".pdfpagenumbering D . 1\n";

- foreach my $fn (sort sortman glob("$dir/man*/*")) {
+ foreach my $fn (sort glob("$dir/man*")) {
+ BuildSec($fn);
+ }
+}
+
+sub BuildSec
+{
+ my $manSdir=shift;
+
+ foreach my $fn (sort sortman glob("$manSdir/*")) {
BuildPage($fn);
}
}

I didn't think of this as an optimization, but rather to move code from
BuildPage() into BuildSec(). However, since it doesn't block until all
of the pages are sorted, it reduces the latency of the script (that's my
guess).

I think moving stuff from BuildPage() to BuildSec() would both simplify
and optimize, so please check it when you can. (I'm also checking it,
but while I'm learning Perl with this, I'm still very limited.)