chicken-hackers
[Top][All Lists]
Advanced

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

[Chicken-hackers] [PATCH] Slight promise efficiency and memory improveme


From: Moritz Heidkamp
Subject: [Chicken-hackers] [PATCH] Slight promise efficiency and memory improvements
Date: Mon, 05 Nov 2012 16:25:18 +0100

Dear Chickeneers,

the attached patch changes the implementation of promises to be slightly
more efficient when forcing a promise more than once (one procedure call
less). Also, instead of keeping the promise result in the promise
thunk's closure it is now kept in a slot of the promise structure. This
allows for removing the reference to the thunk once the promise has been
forced and thus saving some memory. I measured its effect by running the
following program with and without the patch:

  (define seq
    (let next ((n 0))
      (cons n (delay (next (+ n 1))))))

  (define (run)
    (print
     (time
      (let loop ((seq seq))
        (if (< (car seq) 1000000)
            (loop (force (cdr seq)))
            (car seq)))))
    (print (memory-statistics)))


  (run)
  (run)

The results of which are:

without patch:

  0.856s CPU time, 0.352s GC time (major), 500000 mutations, 9/1539 GCs 
(major/minor)
  500000
  #(268435456 230448536 1048576)
  0.034s CPU time, 0/213 GCs (major/minor)
  500000
  #(268435456 230448536 1048576)

with the patch:

  0.506s CPU time, 0.233s GC time (major), 500000 mutations, 11/1500 GCs 
(major/minor)
  500000
  #(134217728 107357264 1048576)
  0.03s CPU time, 0/198 GCs (major/minor)
  500000
  #(134217728 107357264 1048576)

Hope it's of interested and not fatally flawed!

Moritz

Attachment: 0001-Make-promises-slightly-more-efficient-and-less-memor.patch
Description: Text Data


reply via email to

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