[luatex] how many bytes for fontdimens?

jfbu jfbu at free.fr
Thu Aug 5 09:50:06 CEST 2021


Hi,

replying on-list on one topic, as this will be relatively brief (off-list material at start but last topic is luatex related):

> Le 3 août 2021 à 19:10, Hans Hagen <j.hagen at xs4all.nl> a écrit :
> 
>> I have also not tried to optimise how this \Replicate should be used, deciding to nest it with an inner one replicating 1000 times, but never testing if that was actually good.  [...]
> 
> maybe don't pass the number but put it in a register ;

first thing that the macro does anyhow is to make sure it handles explicit digits, the original used \the\numexpr and this version sticks to Knuth and has a reduced interface requiring user to call it with explicit digits or with « \the\somecount » so a single \expandafter does the job.

And in inner inner loops, only a variant doing hard-coded 1000 repetitions is used and has no argument

> this romannumeral is also kind of strange (not sure why you need it

you are absolutely right. It serves nothing in this context. The original is from an area where I provide most macros in two forms say « \Foo » and « \foo » where \Foo expands to \romannumeral\foo (to be precise rather \romannumeral0\foo due to legacy reasons of relative ignorance 8 years ago, but here for this replicate, it is indeed \romanumeral\foo). This means you can do \expandafter\Stuff\romannumeral\foo rather than \expandafter\expandafter\expandafter\Stuff\Foo.

In the case at hand the core expansion is anyhow \csname governed and one could re-organize stuff so that \Foo would be \csname\foo rather, with some micro gain. But this would have been at odds with the style in the original codebase from which it is extracted.

In this specific usage, definitely I could drop the \romannumeral and the paired closing \z at . Will keep this in mind when I will review sieve code for small improvements.

> ; actually you should time romannumeral in pdftex vs luatex .. could be more efficient in thelater

The \romannumeral in my context (sic) are only there to trigger and end expansion... I needed to scratch a bit my head to benchmark that in a way allowing to compare pdftex vs luatex, and I am not sure I do it right. But here we go, typical results on my hardware are listed below and are... surprising to me.

-------- START OF TEST FILE
\long\def\Lots#1{\Repx{\Repm{#1}}}% 10000
\long\def\Repm#1{\Repc{#1#1#1#1#1#1#1#1#1#1}}
\long\def\Repc#1{\Repx{#1#1#1#1#1#1#1#1#1#1}}
\long\def\Repx#1{#1#1#1#1#1#1#1#1#1#1}

\ifdefined\directlua
% copied from https://tex.stackexchange.com/a/32531
  \directlua{pdfelapsedtimer_basetime=0}%
  \def\pdfresettimer{\directlua{pdfelapsedtimer_basetime = os.clock()}}%
  \def\pdfelapsedtime{\numexpr\directlua{tex.print(math.floor((os.clock()-pdfelapsedtimer_basetime)*65536+0.5))}\relax}%
\fi

\catcode`@ 11
%\def\empty{}
%\z@ is a dimen set to 0pt
\let\Tall\z@
\let\Uall\z@

\Repx{%
\immediate\write128{}%
\pdfresettimer
\Lots{\romannumeral\Repm\empty\z@}% 10000 times a r triggered silly expan.
\edef\T{\the\dimexpr\pdfelapsedtime sp}%
\immediate\write128{with: \T}%
\pdfresettimer
\Lots{\Repm\empty}%
\edef\U{\the\dimexpr\pdfelapsedtime sp}%
\immediate\write128{without: \U}%
% update totals
\edef\Tall{\the\dimexpr\Tall+\T}%
\edef\Uall{\the\dimexpr\Uall+\U}%

% always strange things with timer so redo it with order reversed after a \par
\pdfresettimer
\Lots{\Repm\empty}%
\edef\U{\the\dimexpr\pdfelapsedtime sp}%
\immediate\write128{without: \U}%
\pdfresettimer
\Lots{\romannumeral\Repm\empty\z@}% 10000 times a r triggered silly expan.
\edef\T{\the\dimexpr\pdfelapsedtime sp}%
\immediate\write128{with: \T}%

% update totals
\edef\Tall{\the\dimexpr\Tall+\T}%
\edef\Uall{\the\dimexpr\Uall+\U}%
}%

\immediate\write128{}
\immediate\write128{with (total): \Tall}
\immediate\write128{without (total): \Uall}
\immediate\write128{with minus without: \the\dimexpr\Tall-\Uall}
\bye
-------- END OF TEST FILE

% pdftex
with (total): 5.34964pt
without (total): 5.45686pt
with minus without: -0.10722pt

with (total): 5.55394pt
without (total): 5.61536pt
with minus without: -0.06142pt

with (total): 5.35501pt
without (total): 5.3827pt
with minus without: -0.0277pt

% luatex
with (total): 6.08586pt
without (total): 6.30107pt
with minus without: -0.21521pt

with (total): 6.06969pt
without (total): 6.35312pt
with minus without: -0.28343pt

with (total): 6.11238pt
without (total): 6.37778pt
with minus without: -0.2654pt


Conclusion is that it seems to *speed up* « expanding to empty » to *add* \romannumeral wrapper.... 

and indeed with luatex the relative gain is even higher than with pdftex... implying \romannumeral is even more efficient there


Kind regards
Jean-François
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/luatex/attachments/20210805/a1dd973e/attachment.html>


More information about the luatex mailing list.