[luatex] LuaTeX precompilation
Hans Hagen
j.hagen at xs4all.nl
Thu Dec 21 10:27:48 CET 2023
On 12/21/2023 8:55 AM, Henrik Mannerström wrote:
> On Wed, Dec 20, 2023 at 9:57 PM Hans Hagen <j.hagen at xs4all.nl
> <mailto:j.hagen at xs4all.nl>> wrote:
>
> Did you time how long loading these packagestakes? Things like fonts
> always need to be loaded (and a 8 bit font is way smaller than a 32 bit
> wide font with features). You could try to use latex/luatex with 8 bit
> fonts.
>
>
> Without a precompiled format, pdflatex takes 1.2s for my four page
> example. That lualatex takes 2.5s is not that big a difference. What my
> question is about is precompiled formats: If I put everything in the
> preample and precompile it, pdflatex takes only 0.56s. /Here/ is the big
> difference. When I'm typing a typical technical note, I have over the
> years developed a workflow where I use latex + editor as a
> wysiwyg-setup. With two windows: one for the pdf and one for the source,
> recompile almost once for every sentence or equation. /It is here/ where
> the difference adds up. Judging by the other posts sparked by my
> question, I'm not the only one that feels the difference.
When I'm in such trial and error mode I normally work on chapters and
processing some 20-30 pages is fast (sub 2 sec). But of coursenothign
can compete with pdftex here, and actually dvi beats pdf here.
> I readily admit that luatex is a wonderful piece of software and I
> really appreciate the work you have done. Could we make it even better?
> From a technical point of view, how hard would it be to have something
> akin to a precompiled format in luatex?
The format contains:
- the state of registers (many more in luatex)
- allocated nodes (often can be neglected)
- macro definitions (depends on the macro package)
and in pdftex
- hyphenation patterns
- fonts when preloaded
In pdftex fonts are always small. In luatex the wide fonts are not
preloaded, nor are patterns. Actually when in pdftex you emulate utf8
there can be some impact. Making a context format:
pdftex (with mkii) : 7 sec, 4.1 sec when output piped to file
luatex (with mkiv) : 4 sec, 3.2 sec when output piped to file
luametatex (with mkxl) : 2 sec, 1.6 sec when output piped to file
these are rought timings and the non piped are a bit higher when we use
a 4K display and full screen console. Keep in mind that terminal output
(as well as runtime enabled synctex when processing a file) have impact
on your run. Actually, in luametatex/mklx (aka lmtx) we could avoid a
format at the cost of 1 sec extra runtime but that would not work well
on networks.
Because luatex is 32 bit it's format file is larger (just run gzip -d on
a format file to see its real size). Every token in a linked list (macro
body) takes 8 bytes, so you can do your math here wrt preloading more. A
node can be even more. Of course it can save some startup time but it
also adds to the unzipping pipeline.
There is a hit of optimization in luatex for storing registers but zeros
zip good anyway. Explaining the reasons for luametatex being faster is
beyond this thread as it's only used in context.
Adding pattern to the format is possible but I bet that preloading some
15 of them will have a negative impact (there's a reason we delay
loading; keep in mind that when we developed luatex we aslso spent quite
some time on eleminating impact on performance).
Adding fonts to a format would be complex when there's also lua code
involved (much lives in lua memory in rather complex structures). A no-go.
Another topic that comes up regularly is to keep tex in memory but
adding save state and revert to prestine would add a lot complexity to a
macro package (whet to reset and forget) and in the end realoading a
format is faster.
One thing you should keep in mind is that with ssd and proper os file
cching, there's often little to gain by preloading. TeX is very fast in
parsing input and expanding macros but of course it does depend on what
gets loaded. You can gain on some expansion, string macro bodies, and
checking and so, but then it nmakes sense to time that per component to
get an idea (for instance loading tikz runtime has quite some impact but
so might having it in the format).
I stop here as I've written plenty about performance the last decades in
various docs,
Hans
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
More information about the luatex
mailing list.