Re: The myth of fingerprints, er, no, garbage collectors
"Marco Antoniotti (as marco dot antoniotti at unimib dot it)" <[email protected]> Thu, 25 Jun 2026 18:22:15 +0200
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <CAG0Nw2m0OtDEr8VBERfD-qFTr8eKd5BAkMnMgJpzdTJ23wXJTw@mail.gmail.com> |
--0000000000001ec97606551666d9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Rewrite it in Rust =F0=9F=99=84 On Thu, Jun 25, 2026 at 6:19=E2=80=AFPM Tim Bradshaw (as tfb at tfeb dot or= g) < [email protected]> wrote: > Given this silly function: > > (defun smash (n m) > (declare (type fixnum n m)) > (let ((c nil)) > (dotimes (i n c) > (setf c (cons 1 (if (zerop (mod i m)) nil c)))))) > > You can time it. (smash (expt 10 9) 10)) allocates about 16GB, and takes > 25 seconds. GC time is about 0.3% of that time. > > You can also watch GC time grow as it has to copy more: (smash (expt 10 9= ) > 1000) makes lists which can grow to 1000 elts: GC now is well over 0.5% o= f > the time. Keeping lists of a million elements results in the GC taking 10= % > of the runtime. > > The reason I have been playing with all these things is I keep finding > myself writing functions which carefully allow you to, for instance pass = in > some object which they will then reuse instead of allocating one. And > after trying to measure if this was worthwhile, I realised that it almost > never is: it's better to allocate the thing on the fly and throw it away, > because the GC will then never see it at all, whereas if you hold onto it= , > it will. > > As someone who remembers when a GC meant 'you can go and make a cup of te= a > now', modern GCs are wonderful things: we forget how spoiled we are. > > --tim > > _______________________________________________ > Lisp Hug - the mailing list for LispWorks users > [email protected] > http://www.lispworks.com/support/lisp-hug.html > --=20 Marco Antoniotti, Professor, Director tel. +39 - 02 64 48 79 01 DISCo, University of Milan-Bicocca U14 2043 http://dcb.disco.unimib.it Viale Sarca 336 I-20126 Milan (MI) ITALY REGAINS: https://regains.disco.unimib.it/ --0000000000001ec97606551666d9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Rewrite it in Rust=C2=A0=F0=9F=99=84</div><br><div class= =3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr= ">On Thu, Jun 25, 2026 at 6:19=E2=80=AFPM Tim Bradshaw (as tfb at tfeb dot = org) <<a href=3D"mailto:[email protected]">[email protected]</= a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0p= x 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Gi= ven this silly function:<br> <br> (defun smash (n m)<br> =C2=A0 (declare (type fixnum n m))<br> =C2=A0 (let ((c nil))<br> =C2=A0 =C2=A0 (dotimes (i n c)<br> =C2=A0 =C2=A0 =C2=A0 (setf c (cons 1 (if (zerop (mod i m)) nil c))))))<br> <br> You can time it.=C2=A0 (smash (expt 10 9) 10)) allocates about 16GB, and ta= kes 25 seconds.=C2=A0 GC time is about 0.3% of that time.<br> <br> You can also watch GC time grow as it has to copy more: (smash (expt 10 9) = 1000) makes lists which can grow to 1000 elts: GC now is well over 0.5% of = the time. Keeping lists of a million elements results in the GC taking 10% = of the runtime.<br> <br> The reason I have been playing with all these things is I keep finding myse= lf writing functions which carefully allow you to, for instance pass in som= e object which they will then reuse instead of allocating one.=C2=A0 And af= ter trying to measure if this was worthwhile, I realised that it almost nev= er is: it's better to allocate the thing on the fly and throw it away, = because the GC will then never see it at all, whereas if you hold onto it, = it will.<br> <br> As someone who remembers when a GC meant 'you can go and make a cup of = tea now', modern GCs are wonderful things: we forget how spoiled we are= .<br> <br> --tim<br> <br> _______________________________________________<br> Lisp Hug - the mailing list for LispWorks users<br> <a href=3D"mailto:[email protected]" target=3D"_blank">lisp-hug@lispwo= rks.com</a><br> <a href=3D"http://www.lispworks.com/support/lisp-hug.html" rel=3D"noreferre= r" target=3D"_blank">http://www.lispworks.com/support/lisp-hug.html</a><br> </blockquote></div><div><br clear=3D"all"></div><br><span class=3D"gmail_si= gnature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_signature"><d= iv dir=3D"ltr"><div><span style=3D"font-family:monospace">Marco Antoniotti,= Professor, Director =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 tel. +39 - = 02 64 48 79 01<br>DISCo, University of Milan-Bicocca U14 2043=C2=A0=C2=A0 <= a href=3D"http://dcb.disco.unimib.it" target=3D"_blank">http://dcb.disco.un= imib.it</a><br>Viale Sarca 336<br>I-20126 Milan (MI) ITALY<br><br></span></= div><span style=3D"font-family:monospace">REGAINS: <a href=3D"https://regai= ns.disco.unimib.it/" target=3D"_blank">https://regains.disco.unimib.it/</a>= <br></span></div></div> --0000000000001ec97606551666d9-- _______________________________________________ Lisp Hug - the mailing list for LispWorks users [email protected] http://www.lispworks.com/support/lisp-hug.html