Re: PNG loading time

Max Chernoff via tex-live <[email protected]>
Newsgroups gmane.comp.tex.live
Message-ID <[email protected]>
Hi Reinhard,

On Thu, 2026-02-12 at 03:09 +0100, Reinhard Kotucha wrote:
> On 2026-02-11 at 18:10:52 -0700, Max Chernoff via tex-live wrote:
>
>  > Is each image only included once in this test document, or does it
>  > include the same image multiple times? pdfTeX always closes images
>  > at the end of every page, so including the same image on multiple
>  > different pages means that it reloads it every time;
>
> Each image is loaded only once.

I was thinking of including PDF files, where it makes a huge difference
if you include multiple pages on the same page or on different pages.
Example:

    %% Setup code
    {
        \endlinechar=-1
        \everyeof{\noexpand}
        \xdef\pgfmanualpath{\input{|kpsewhich --format=doc pgfmanual.pdf}}
    }
    \def\includeimage#1{%
        \message{^^J#1}%
        \pdfximage #1 {\pgfmanualpath}%
        \pdfrefximage\pdflastximage%
    }
    \def\forcepagebreak{\null\vfill\eject}
    \newcount\loopcounter

    %% Demonstration
    \loopcounter=1
    \pdfresettimer
    \loop\ifnum\loopcounter<10
        \includeimage{width 10pt height 10pt page \the\loopcounter}%
        \advance\loopcounter by 1
    \repeat
    \forcepagebreak
    \message{^^J^^JSingle page: \the\numexpr\pdfelapsedtime / 66\relax ms^^J}

    \loopcounter=1
    \pdfresettimer
    \loop\ifnum\loopcounter<10
        \includeimage{width 10pt height 10pt page \the\loopcounter}%
        \advance\loopcounter by 1
        \forcepagebreak
    \repeat
    \message{^^J^^JMultiple pages: \the\numexpr\pdfelapsedtime / 66\relax ms^^J}

    \bye

This gives me the following output:

    Single page: 1631ms
    Multiple pages: 13820ms

so loading all the pages on a single page is almost 10x faster than
loading all the pages on separate pages. But I've done some testing and
you do seem to be right that this doesn't apply at all for .png files.

> \pdfximage loads the image and
> returns an object number.  With \pdfrefximage you can use this object
> multiple times.

I knew that you _can_ use this object multiple times, but I though that
LaTeX/graphicx didn't. But checking the source, it looks like it's
correctly reused the objects since 2017.

Thanks,
-- Max
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.