[luatex] Removing the zero-initialization of an array can speedup LuaTeX on plain TeX document by 25%
Hans Hagen
j.hagen at xs4all.nl
Sat Aug 31 21:50:33 CEST 2024
On 8/31/2024 7:12 PM, luigi scarso wrote:
>
>
> On Sat, 31 Aug 2024 at 15:17, user202729--- via luatex <luatex at tug.org
> <mailto:luatex at tug.org>> wrote:
>
> Hi,
>
> Do you think the following is a reasonable possible performance
> improvement for LuaTeX? Thank you.
>
> ------
>
> In the hnj_hyphenation function, currently the large array
> `utf8word` is zeroed out every time the function is called.
>
> This is unnecessary (the string is always null-terminated before
> being used. Besides, observe that the function processes multiple
> words per call, without zeroing out the array between each word, so
> even with the current function there could be nonzero bytes after
> the null terminator at each use of the array).
>
> For a plain TeX file where macro expansion takes negligible time
> (such as tex.tex, the source code of TeX), this single improvement
> can speeds up the compilation time by 25%. On my machine, the
> runtime decreases from 3.064s to 2.327s.
>
> To generate `tex.tex`, you can download `tex.web` from CTAN package
> `tex`, and run `weave tex.web`
hm. .. we're talking luate here so where does the patch and measurements
apply to?
> The patch is attached below.
for tex.web?
> Thank you very much, surely Hans or me will check it asap.
A few remarks:
we have MAX_WORD_LEN set to 64K but than can just be (as in luametatex)
1K; maybe even less as the engine has some limits on word lengths
elsewhere anyway
this only kicks in when for esceptions and normally there's only a
handful of them so unless one has many thousands of exceptions the
initialization time can be neglected (and it happens only when
exceptions are loaded)
on 400 10 character exceptions i see no gain (on a 5 year old laptop) as
we're in the random runtime measurements; runs only differ in the second
decimal so .452 .. .454 which makes it hard to check fo it matters
actually, when one has many exceptions the penalty is in the hyphenation
routine itself as there the lookups contribute soem to runtime
that said: i have no problem with not zeroing but a 25% performance gain
is not what happens here (unless a clear example shows this) .. a 3.0
second plain run with no macros being used is not that fast anyway)
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.