[Tex/LaTex] pdflatex – how to find bottleneck of long compiling time for the document

compilingpdftex

I'm having (again/still) a very large LateX document which I'm working on.

  • >340 pages
  • many graphics (mostly included pdf, but also some PNG or others)
  • many tables (also longtables)
  • resulting PDF is >18 MB in size
  • many references and citations

Compilation takes between 2 and 7 minutes normally. I'm using latexmk for complete compiling, so the given times normally is for several latex runs in total.

Nevertheless I'd like to speed up the process of recompiling and try to find the bottlenecks. When I see the console output, it seems to hang at some points where compiling takes longer.

Is there a way to analyze which steps takes how much time and thus find those 20% of the things which might cause 80% of the compiling time?

E. g. can I print the duration it takes to process each page and so see which pages take the most time to build?


Pareto rules:

Thanks to @Robert 's answer, I now have the compiling times of each page and

  • indeed it is about 20 pages of the 340 which take more than 50% of the compiling time!
  • 2 pages even need about 20 s for compiling!
  • none of those "slow pages" seems to include PNG images

Very strange, I'll have to dig deeper – maybe cross references or fixme remarks are the problem?!

Best Answer

You could build your timer with \pdfelapsedtime:

\usepackage{atbegshi}
\newcommand\showtimer{%
  \message{^^Jtimer: \the\numexpr\the\pdfelapsedtime*1000/65536\relax}%
  \pdfresettimer}
\AtBeginDocument{\showtimer}
\AtBeginShipout {\showtimer}

would print the time it took (in milliseconds) for each page to be output (here p. 231 took 103ms, p. 232 took 44ms):

timer: 103 [231] 
timer: 44 [232] 

Note that due to the asynchronous nature of tex's output routine, this isn't completely exact: firstly, the page breaker usually only kicks in after a paragraph break, so that material that will actually end up on the next page (or even pages for very long paragraphs) has already been processed; secondly, inserts (floats, footnotes) may have been processed already earlier -- for example, split footnotes or floats that didn't fit on the previous page(s). So the numbers may actually measure the processing time both of material from previous and from later pages.


For evaluation you can extract those lines:

grep '^timer:' filename.log > Compiletime.txt