Adding Java and C++ to the MQTT benchmarks or: How I Learned to Stop Worrying and Love the Garbage Collector
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Wed Jan 8 14:43:26 PST 2014
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.
More information about the Digitalmars-d
mailing list