[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

#1710: Major garbage collector runs all the time

From: Chicken Trac
Subject: #1710: Major garbage collector runs all the time
Date: Sun, 02 Aug 2020 15:31:46 -0000

#1710: Major garbage collector runs all the time
            Reporter:  megane   |       Type:  defect
              Status:  new      |   Priority:  major
           Milestone:  someday  |  Component:  core libraries
             Version:  5.2.0    |   Keywords:  runtime
Estimated difficulty:  easy     |
 The major garbage collector runs too frequently if you happen to get
 "correct" combination of
 - heap size,
 - total size of "permanent objects", and
 - you're generating lots of garbage objects.

 (By permanent objects I mean the set of objects that survives a major

 In this situation you can effectively get a major GC for every `N`
 bytes that survive the 1st generation.

 This `N` is basically just `heap_size - permanent_objects`, i.e. the free
 space just after a major collection.

 In practice, the `N` may get quite small. In this case the program is
 just doing garbage collection.

 One incarnation of this is a program that gradually gets slower and
 slower, and
 then suddenly gets fast again. In this case the sum of permanent objects
 bigger and bigger until the objects no longer fit in the heap. At this
 point the
 heap is grown and everything gets smooth again.

 One possible workaround is to manually specify a big heap with `-:h` or
 This has the side-effect of
 1. Making finalizers run less often (they are checked during each major
 2. Causing memory fragmentation. (Objects are compacted during the major
 3. You have to choose a size. With `-:hi` you can still run into the
 problem if
    you choose too small size.

 One example of affected program:
 (define *corpus*
   (call-with-input-file "largeish_file.txt"
     (lambda (input-file)
       (let loop ([line (read-line input-file)]
                  [tokens '()])
         (if (eof-object? line)
             (loop (read-line input-file)
               (append tokens (string-split line))))))))

 This program generates lots of garbage by creating lots of temporary
 Using big heap (using `-:h`) makes things a lot faster.

 I've posted a patch here:
 This works by growing the heap if it's too full after a major collection.

Ticket URL: <>
CHICKEN Scheme <>
CHICKEN Scheme is a compiler for the Scheme programming language.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]