Tim Rentsch said:
Folklore. Measurements of real programs using, eg, the Boehm collector,
show macro-scale performance similar to, or better than, the same
program using manual rather than automatic reclamation. Micro-scale
When one has nested lifetimes of objects, life is simple: one can
use automatic storage. The problems begin when lifetimes are dynamic,
which usually means that to keep track of the objects at all, one
will build some kind of graph. When that graph is a tree and the
lifetimes of subtrees do not exceed the lifetime of their supertrees,
subtrees can be free whenever their supertree is freed, which often
is still quite simple. But when the graph has a more general form,
one usually has to implement some form of reference counting or
marking scheme, which effectively is a garbage collector (Greenspun's
tenth law).
Some notes I have collected on the subject (repost):
»There were two versions of it, one in Lisp and one in
C++. The display subsystem of the Lisp version was faster.
There were various reasons, but an important one was GC:
the C++ code copied a lot of buffers because they got
passed around in fairly complex ways, so it could be quite
difficult to know when one could be deallocated. To avoid
that problem, the C++ programmers just copied. The Lisp
was GCed, so the Lisp programmers never had to worry about
it; they just passed the buffers around, which reduced
both memory use and CPU cycles spent copying.«
<
[email protected]>
»A lot of us thought in the 1990s that the big battle would
be between procedural and object oriented programming, and
we thought that object oriented programming would provide
a big boost in programmer productivity. I thought that,
too. Some people still think that. It turns out we were
wrong. Object oriented programming is handy dandy, but
it's not really the productivity booster that was
promised. The real significant productivity advance we've
had in programming has been from languages which manage
memory for you automatically.«
http://www.joelonsoftware.com/articles/APIWar.html
»[A]llocation in modern JVMs is far faster than the best
performing malloc implementations. The common code path
for new Object() in HotSpot 1.4.2 and later is
approximately 10 machine instructions (data provided by
Sun; see Resources), whereas the best performing malloc
implementations in C require on average between 60 and 100
instructions per call (Detlefs, et. al.; see Resources).
And allocation performance is not a trivial component of
overall performance -- benchmarks show that many
real-world C and C++ programs, such as Perl and
Ghostscript, spend 20 to 30 percent of their total
execution time in malloc and free -- far more than the
allocation and garbage collection overhead of a healthy
Java application (Zorn; see Resources).«
http://www-128.ibm.com/developerworks/java/library/j-jtp09275.html?ca=dgr-jw22JavaUrbanLegends
»Perhaps the most important realisation I had while developing
this critique is that high level languages are more important
to programming than object-orientation. That is, languages
which have the attribute that they remove the burden of
bookkeeping from the programmer to enhance maintainability and
flexibility are more significant than languages which just
add object-oriented features. While C++ adds object-orientation
to C, it fails in the more important attribute of being high
level. This greatly diminishes any benefits of the
object-oriented paradigm.«
http://burks.brighton.ac.uk/burks/pcinfo/progdocs/cppcrit/index005.htm
»The garbage collector in contemporary JVMs doesn't touch most
garbage at all. In the most common collection scenario, the JVM
figures out what objects are live and deals with them exclusively
-- and most objects die young. So by the time they get to garbage
collection, most objects that have been allocated since the last
garbage collection are already dead. The garbage collector avoids
a lot of work it would have to do if it were doing it one piece
at a time. Similarly, the JVM can optimize away many object
allocations.«
http://java.sun.com/developer/technicalArticles/Interviews/goetz_qa.html