memory leak in decimal/binary?

Martin Budaj <[email protected]> Fri, 3 Feb 2023 21:00:46 +0100
Newsgroups gmane.comp.tex.metapost
Message-ID <CALPsdSvkzZiXa7w=LXdO51UE6ARQ0A9BeG2MbV0JX4b5rcCABA@mail.gmail.com>
Hi,

I've encountered an enormous memory usage (and long run times) of mpost
when running in the decimal/binary mode and processing a lot of stored
paths.

It can be demonstrated on the following cycle (the exact path definition
doesn't matter but should be long enough to make the issue obvious):

path p;
for i:= 0 upto 4000:

p:=(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..

 (0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40)..(0,0)..(10,10)..(2,8)..(5,40);
endfor;
end.

It uses gigabytes of memory in the decimal mode (and somewhat less in
binary), so something is probably going wrong:

        Command being timed: "mpost --numbersystem=scaled test.mp"
        User time (seconds): 1.42
        Maximum resident set size (kbytes): 40768

        Command being timed: "mpost --numbersystem=double test.mp"
        User time (seconds): 0.61
        Maximum resident set size (kbytes): 41728

        Command being timed: "mpost --numbersystem=decimal test.mp"
        User time (seconds): 498.56
        Maximum resident set size (kbytes): 37244480

        Command being timed: "mpost --numbersystem=binary test.mp"
        User time (seconds): 187.32
        Maximum resident set size (kbytes): 10906672

After some experiments with the number of loop repetitions it seems that
the memory usage (and the run time) increases linearly with the number of
iterations.

MP version: This is MetaPost, version 2.02 (TeX Live 2022/Debian) (kpathsea
version 6.3.4)

Best wishes
Martin

--
http://tug.org/metapost/