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

Tradeoffs with resources



    Date: Thu, 20 Sep 90 13:29:18 -0700
    From: jbarnett@nrtc.northrop.com (Jeff Barnett)

    I am interested in using resources but can't tell where the break-even
    and big-win points are from the documentation.  Therefore, the following
    (probably too vague) questions:

    (1) How much consing does the resource facility do (independent of the
	froms [forms?] I supply) when an object is created?

None (at least on an Ivory under 8.0).  Here's how I tested it:

1     (defresource my-resource () :constructor (make-array 10))
    
     (defun use-and-release-resource (&key first-time)
      (when first-time
        (clear-resource 'my-resource))
      (format t "~&The resource itself occupies ~D word~:p."
	      (time (return-size-of-resource))))
    
     (defun return-size-of-resource ()
      (using-resource (foo my-resource)
        (sys:%structure-total-size foo)))
    
     (use-and-release-resource :first-time t)
     [...]
     11 structure words consed in WORKING-STORAGE-AREA.
     The resource itself occupies 11 words.

0    (2) How much consing does the resource facility do (independent of the
	froms [forms?] I supply) when an object is reallocated?
None:
1     (use-and-release-resource :first-time nil)
     [...]
     The resource itself occupies 11 words.

0    (3) What are guidelines as to minimum size objects that are good to put
	in resources?
I don't know of a simple answer.  See below.
    (4) How rapidly must the average object be reallocated for using resources
	to make sense --- this question assumes that the longer the lifetime
	of a single use, the less good the resource idea.
Not necessarily.  Reusing the same 10-word block of storage 10,000 times in a
few minutes saves the time it would take to cons and garbage collect 100,000
words.  I suspect the answer depends on a lot of factors, like how fast
the test function for your resource runs, and even on how much physical memory
you have compared to the working set of your program -- if a consed object
doesn't become garbage until after it's swapped out, it should run a lot
slower than if the EGC handles it while it's still in physical memory.
    (5) Is the resource mechanism smart enough to release, to the GC, objects that
	are not in use when the GC is prepared to reclaim them, i.e., are objects
	not in use copied by the GC because the "resource array" points at them?
Not by default, but you can say
	(si:define-gc-cleanup clear-my-resource ("Clear my resource")
	  (clear-resource 'my-resource))
to add it to the list that Start GC :Immediately or Start GC :Cleanup Ask
gives you.  If you're concerned about keeping them from being "copied by the
GC", not in saving virtual memory, you can use a static area (like
sys:permanent-storage-area).

					--Kanef