unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Arne Babenhauserheide <arne_bab@web.de>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-user@gnu.org
Subject: Re: out-of-control GC
Date: Wed, 13 Sep 2017 21:38:57 +0200	[thread overview]
Message-ID: <8760cm8jsn.fsf@web.de> (raw)
In-Reply-To: <87d16ve3oq.fsf@netris.org>

[-- Attachment #1: Type: text/plain, Size: 1746 bytes --]

Hi Mark,

Thank you for your great writeup!

Mark H Weaver <mhw@netris.org> writes:
> * The (format #f ...) allocates a temporary string output port, and that
>   with.  Using 'number->string' there would reduce memory allocation of
>   the loop above by an order of magnitude or more.
> * The fact that you're using 'set!' to mutate 'longer' forces a
>   heap-allocated variable object to be allocated for 'longer', whereas
>   otherwise it could be allocated on the stack.  See section 9.3.4
>   (Variables and the VM) in the Guile 2.2 manual for more on this, and
>   how 'set!' often makes things much less efficient.
>
> * Since 'longer' is allocated within the loop, a new copy of that
>   (heap-allocated) variable object is created for each iteration.

I implemented a version which avoids both points via let-recursion and
number->string:

    (define (make-bgl lis cnt)
      "a bogus longer list"
      (let loop ((longer (cons (number->string cnt) lis))
                 (cnt cnt))
        ;; periodically report statistics
        (when (eq? 0 (modulo cnt (* 1000 1000)))
          (begin (format #t "~A " cnt)  (avg-gc-cpu-time)))
        (cond
         ;; periodically trim the list
         ((and (eq? 0 (modulo cnt (* 4123 1123)) (> (length longer) 0)))
          (loop (list)
                cnt))
         ;; end recursion
         ((eq? 0 cnt)
          lis)
         (else
          (loop (cons (number->string cnt) longer)
                (- cnt 1))))))

This does indeed spend much less time in GC, but its memory usage is
still rising rapidly. Did I unknowingly create a memory leak?

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2017-09-13 19:38 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-09 19:47 out-of-control GC Linas Vepstas
2017-09-10  4:14 ` Linas Vepstas
2017-09-10 16:50   ` Arne Babenhauserheide
2017-09-10 18:03     ` David Kastrup
2017-09-10 20:23     ` Linas Vepstas
2017-09-10 20:36       ` Marko Rauhamaa
2017-09-10 21:47         ` Linas Vepstas
2017-09-10 22:38           ` Marko Rauhamaa
2017-09-11 16:17             ` Arne Babenhauserheide
2017-09-14 18:31             ` Linas Vepstas
2017-09-14 18:58               ` Marko Rauhamaa
2017-09-14 20:15                 ` Linas Vepstas
2017-09-14 20:36                   ` David Kastrup
2017-09-14 20:45                 ` Arne Babenhauserheide
2017-09-11  8:22           ` tomas
2017-09-14 20:19             ` Linas Vepstas
2017-09-13 17:13         ` David Kastrup
2017-09-10 22:17       ` Arne Babenhauserheide
2017-09-10 22:36       ` Arne Babenhauserheide
2017-09-14  7:44       ` Mark H Weaver
2017-09-10 16:53   ` Arne Babenhauserheide
2017-09-13  2:24   ` Mark H Weaver
2017-09-13 19:38     ` Arne Babenhauserheide [this message]
2017-09-13 19:57       ` David Kastrup
2017-09-13 20:37         ` Arne Babenhauserheide
2017-09-14 19:14     ` Linas Vepstas
2017-09-11 18:13 ` Hans Åberg
  -- strict thread matches above, loose matches on Subject: below --
2017-09-11  7:42 Kjetil Matheussen
2017-09-14 18:41 ` Linas Vepstas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8760cm8jsn.fsf@web.de \
    --to=arne_bab@web.de \
    --cc=guile-user@gnu.org \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).