Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!travelers.mail.cornell.edu!news.kei.com!news.mathworks.com!newsfeed.internetmci.com!howland.reston.ans.net!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!hplabs!hplntx!hplntx.hpl.hp.com!gjr
From: gjr@hplgr2.hpl.hp.com (Guillermo (Bill) J. Rozas)
Subject: Re: Is Garbage Collection faster?
Sender: news@hpl.hp.com (HPLabs Usenet Login)
Message-ID: <GJR.95Oct10170019@hplgr2.hpl.hp.com>
In-Reply-To: jeff@cogsci.ed.ac.uk's message of Thu, 5 Oct 1995 16:18:40 GMT
Date: Wed, 11 Oct 1995 01:00:19 GMT
Reply-To: gjr@hplabs.hpl.hp.com
References: <44uskp$4g6@news.inc.net> <450m7f$77h@camelot.ccs.neu.edu>
	<DFzHB6.654@cogsci.ed.ac.uk>
Nntp-Posting-Host: hplgr2.hpl.hp.com
Organization: /users/gjr/.organization
Lines: 45

In article <DFzHB6.654@cogsci.ed.ac.uk> jeff@cogsci.ed.ac.uk (Jeff Dalton) writes:

|   I've heard that there are some benchmark results that show
|   Scheme fatser than C (?) because of garbage collection.
|   I've variously heard that the results are due to (a) Will
|   Clinger, and (b) Richard O'Keefe.
|
|   Can anyone supply -- or tell me where to find -- details of
|   these or similar results?

If you tie your hands a little (or you tie your compiler's hands a
little) you can use garbage collection in a C program as well.

As an anecdote, I'll relate the following.

The optimizer for the compiler that I've been working on -- written in
C -- was doggedly slow at one point (it is not a speed demon now, but
being a prototype that is not one of its goals).  I profiled it and it
was spending 90% of its time in the free routine.

My first thought was that I had a poor malloc/free combination.  I
tried a few other versions (including the GNU version) and things did
not improve, in fact, they became worse.  It became apparent to me
that since many programs hardly ever free (they release memory by
dying), the standard implementations are very biased towards speeding
up malloc at the expense of free.  God help you if you actually free
everything that you no longer need.

Since I had just written a graph marking algorithm for the third time
-- it's the sort of nonsense you have to do in order to correctly free
a graph with sharing and cycles -- I decided that I had spent too much
time (mine and the computer's) using tools from the dark ages.

I wrote a low-tech synchronous (invoked at "known good points")
non-conservative copying collector, and overnight my optimizer sped up
by a factor of 10.

I'm sure that I could have reused storage more carefully in my
optimizer.  The point is, why should I worry about things like that
when 30-year-old technology can make the problem disappear?

In my experience garbage collection is ALWAYS faster than malloc/free.
It takes ME considerably less time to write a program if I assume the
presence of a garbage collector than if I do not.  Occasionally the
program will run faster as well, but that is largely a bonus.
