Adding Java and C++ to the MQTT benchmarks or: How I Learned to Stop Worrying and Love the Garbage Collector

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Jan 8 14:50:05 PST 2014


On Wed, Jan 08, 2014 at 11:43:26PM +0100, Joseph Rushton Wakeling wrote:
> On 08/01/14 23:23, Benjamin Thaut wrote:
> >No, this expierence is not only based of this. I observed multiple
> >discussions on the newsgroup, where turning off the GC would speed up
> >the program by factor 3.
> 
> In my experience it seems to depend very much on the particular
> problem being solved and the circumstances in which memory is being
> allocated.  Example: I have some code where, at least in the source,
> dynamic arrays are being created via "new" in a (fairly) inner loop,
> and this can be run repeatedly apparently without the GC being
> triggered -- in fact, my suspicion is that the allocated space is
> just being repeatedly re-used and overwritten, so there are no new
> allocs or frees.
> 
> OTOH some other code I wrote recently had a situation where, as the
> data structure in question expanded, a new array was allocated, and
> an old one copied and then deallocated.  This was fine up to a
> certain scale but above a certain size the GC would (often but not
> always) kick in, leading to a significant (but unpredictable)
> slowdown.
> 
> My impression was that below a certain level the GC is happy to
> either over-allocate (leaving lots of space for expansion) and/or
> avoid freeing memory (because there's plenty of memory still free),
> which avoids all the slowdown of alloc/free until there's a
> significant need for it.

So this proves that the real situation with GC vs manual memory
management isn't as simple as a binary "GC is better" or "GC is bad". It
depends a lot on the exact use case.

And now that you mention it, there does seem to be some kind of
threshold where something happens (I wasn't sure what it was before, but
now I'm thinking maybe it's a change in GC behaviour) where there's a
sudden change in program performance, that I've observed recently in one
of my programs. I might have a look into it sometime -- though I was
planning to redo that part of the code anyway, so I may or may not find
out the real reason behind this.


T

-- 
Государство делает вид, что платит нам зарплату, а мы делаем вид, что работаем.


More information about the Digitalmars-d mailing list