[plt-scheme] cost of closure?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu May 31 22:16:35 EDT 2007

At Thu, 31 May 2007 21:01:12 -0500, "Robby Findler" wrote:
> When I run the below I get 42.2 bytes (on average) for 1 cons and 1
> 3-var closure, as compared to 13.76 bytes (on average) for 1 cons and
> one struct. This is according to current-memory-use.

It would be really cool if a 3-value struct plus a cons cell added up
14 bytes! Unfortunately, the run-time system isn't that clever...

100 objects is too small to measure via `current-memory-use'. I turned
up `num' to 100000, and I get right at 40 bytes in both cases. That's
the answer I expect, based on the implementation:

   12 = 4 bytes * 3 fields or captured bindings
    4 = 4 bytes * 1 code (closure) or type (struct) pointer
    4 = 4 bytes * 1 MzScheme type tag and hash code
   12 = 12 bytes per cons cell (MzScheme level)
    8 = 4 bytes * 2 objects for GC's layer of size info
 ----
   40

Add a little bit of page-level GC management overhead, and the result
should be slightly more than 40 bytes per.

Matthew



Posted on the users mailing list.