[Tex/LaTex] Speed up LaTeX compilation on a document with lots of automatically created tables

compilingperformancetables

I know that similar ground has been covered before (e.g. Speeding up LaTeX compilation), but this question is more specific.

I want to create some reports programmatically, so I wrote a program that produces the necessary TeX file. The file contains hundreds of longtable tables (longtabu actually). The compilation time in not acceptable (more than a minute and the reports may get much bigger) and I am searching for ways of decreasing it.

Overally there are 4 types of tables. Each type has the same header line, the same number of rows and the same number of columns. The only thing that changes is the data within the tables. Is it possible to speed up the compilation time?

If it helps, I know the maximum width of each column (although obviously TeX doesn't) and the number of rows for each table type. Is this type of knowledge helpfull at all?

I also thought of creating different *.tex files for each table type, spawning different processes for their compilation and combining them with pdfpages. Has anyone used this technique, or is it going to be a waste of time?

I have already precompiled the preamble, but the gain was very small. The output has to be pdf.

edit

The reason why I do care about the performance is because the compilation is going to be done server-side.

@Yiannis
The following is a mwe of one of the tables' types. The preamble is common in all the tables. I don't use computer modern but I don't think that font selection is relevant in this context. I don't really need the headers to repeat themselves on each page, although it would be nice. On second thought neither alignment to the decimal point is truly necessary, but if I didn't want the output to look nice, I wouldn't have used LaTeX on the first place.

In regard of plain TeX, could you provide some pointers? In the past I have only used LaTeX.

@Bruno
Thank you very much! Your solution is very fast, but it doesn't work with dcolumn and most importantly the spacing is very bad. Try duplicating the table you provided and you will see that the \bottomrule of the first one and the \toprule of the second one have no space between them at all.

\documentclass[a4paper,10pt,fleqn,final]{article}

\usepackage{xcolor}
\usepackage[a4paper,top=2cm,bottom=2cm,left=1.5cm,right=1.5cm]{geometry}
\usepackage{longtable, booktabs, multirow, tabu}
\usepackage{caption}
\usepackage{dcolumn}

\newcolumntype{d}[1]{D{.}{.}{#1}}   
\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}}
\newcommand{\mr}[1]{\multirow{2}{*}{#1}}

\begin{document}

\begin{longtabu}{cd{3.2}cd{3.2}cd{3.2}cd{3.2}cd{3.2}l}
\caption*{Synopsis of P75 - 97-558} \\
\toprule
    \mc{\mr{LoadCase}} &  \multicolumn{2}{c}{$N$} & \multicolumn{2}{c}{$V_{in}$} & \multicolumn{2}{c}{$V_{out}$} & \multicolumn{2}{c}{$M_{in}$} & \multicolumn{2}{c}{$M_{out}$} \\
    \cmidrule(rl){2-3} \cmidrule(rl){4-5} \cmidrule(rl){6-7} \cmidrule(rl){8-9} \cmidrule(rl){10-11}
    &\mc{UF} & State & \mc{UF} & State & \mc{UF} & State & \mc{UF} & State & \mc{UF} & State \\
\midrule
\endhead
\bottomrule
\endlastfoot
\midrule \multicolumn{11}{r}{{Continued on next page}} \\ \bottomrule
\endfoot
21 & 0.80 & Pass & 0.32 & Pass & 0.04 & Pass & 0.05 & Pass & 0.15 & Pass \\
22 & 0.76 & Pass & 0.02 & Pass & 0.03 & Pass & 0.09 & Pass & 0.11 & Pass \\
23 & 0.61 & Pass & 0.32 & Pass & 0.03 & Pass & 0.06 & Pass & 0.10 & Pass \\
24 & 0.56 & Pass & 0.02 & Pass & 0.02 & Pass & 0.06 & Pass & 0.07 & Pass \\
25 & 0.59 & Pass & 0.22 & Pass & 0.03 & Pass & 0.02 & Pass & 0.09 & Pass \\
26 & 0.56 & Pass & 0.02 & Pass & 0.02 & Pass & 0.06 & Pass & 0.07 & Pass \\
27 & 0.58 & Pass & 0.16 & Pass & 0.03 & Pass & 0.00 & Pass & 0.08 & Pass \\
28 & 0.56 & Pass & 0.02 & Pass & 0.02 & Pass & 0.06 & Pass & 0.07 & Pass \\
29 & 0.58 & Pass & 0.14 & Pass & 0.02 & Pass & 0.01 & Pass & 0.08 & Pass \\
30 & 0.56 & Pass & 0.02 & Pass & 0.02 & Pass & 0.06 & Pass & 0.07 & Pass \\
31 & 0.87 & Pass & 0.51 & Pass & 0.06 & Pass & 0.31 & Pass & 0.01 & Pass \\
32 & 0.64 & Pass & 0.31 & Pass & 0.07 & Pass & 0.13 & Pass & 0.03 & Pass \\
33 & 0.66 & Pass & 0.04 & Pass & 0.02 & Pass & 0.15 & Pass & 0.14 & Pass \\
34 & 0.85 & Pass & 0.78 & Pass & 0.01 & Pass & 0.29 & Pass & 0.15 & Pass \\
35 & 54.29 & \bfseries \color{red}Fail & 1.41 & \bfseries \color{red}Fail & 0.03 & Pass & 0.77 & Pass & 0.04 & Pass \\
36 & 6.89 & \bfseries \color{red}Fail & 1.21 & \bfseries \color{red}Fail & 0.00 & Pass & 0.72 & Pass & 0.08 & Pass \\
37 & 3.66 & \bfseries \color{red}Fail & 1.44 & \bfseries \color{red}Fail & 0.05 & Pass & 0.71 & Pass & 0.08 & Pass \\
38 & -1.00 & \bfseries \color{red}Fail & 1.62 & \bfseries \color{red}Fail & 0.02 & Pass & 0.75 & Pass & 0.12 & Pass
\end{longtabu}
\end{document}

Best Answer

If you know the table widths in advance you can "seed" the data that LT writes to the aux file so that it gets the correct widths first time, that won't speed up each run but means that it doesn't take several runs for LT to converge. (Basically look at the format of the command Lt writes to the aux file, recording the column widths, and put that into the document preamble.)

It's possible that compilation speed is improved a bit if you increase LTchunksize, with modern TeX memory requirements you can probably increase that a lot, so the whole table is processed in one chunk.

If you really know all the widths, and don't need any fancy spanning column behaviour, there is always the option of not using the TeX alignment methods at all and just making each row be a row of fixed-width hboxes. that saves TeX the bother of saving all the data in unset boxes, and working out the column widths.

Of course the time taken depends rather on how complicated the cells are, if you got rid of all the table markup and just set each cell as a paragraph, that wouldn't give the layout you want but would give a limit on the achievable time.

Related Question