General performance tip about possibly using the GC or not
Cecil Ward via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 28 17:52:11 PDT 2017
I am vacillating - considering breaking a lifetime's C habits and
letting the D garbage collector make life wonderful by just
cleaning up after me and ruining my future C disciple by not
deleting stuff myself.
I don't know when the GC actually gets a chance to run.
I am wondering if deleting the usual bothersome
immediately-executed hand-written cleanup code could actually
improve performance in a sense in some situations. If the cleanup
is done later by the GC, then this might be done when the
processor would otherwise be waiting for io, in the top loop of
an app, say? And if so this would amount to moving the code to be
run effectively like 'low priority' app-scheduled activities,
when the process would be waiting anyway, so moving cpu cycles to
a later time when it doesn't matter. Is this a reasonable picture?
If I carry on deleting objects / freeing / cleaning up as I'm
used to, without disabling the GC, am I just slowing my code
down? Plus (for all I know) the GC will use at least some battery
or possibly actually important cpu cycles in scanning and finding
nothing to do all the time because I've fully cleaned up.
I suppose there might also be a difference in cache-friendliness
as cleaning up immediately by hand might be working on hot
memory, but the GC scanner coming along much later might have to
deal with cold memory, but it may not matter if the activity is
app-scheduled like low priority work or is within time periods
that are merely eating into io-bound wait periods anyway.
I definitely need to read up on this. Have never used a GC
language, just decades of C and mountains of asm.
Any general guidance on how to optimise cpu usage particularly
responsiveness.
One pattern I used to use when writing service processes (server
apps) is that of deferring compute tasks by using a kind of 'post
this action' which adds an entry into a queue, the entry is a
function address plus arg list and represents work to be done
later. In the top loop, the app then executes these 'posted' jobs
later at app-scheduled low priority relative to other activities
and all handling of io and timer events, when it has nothing else
to do, by simply calling through the function pointer in a post
queue entry. So it's a bit like setting a timer for 0 ms, passing
a callback function. Terminology - A DFC or lazy, late execution
might be other terms. I'm wondering if using the garbage
collector well might fit into this familiar pattern? That fair?
And actually even help peformance for me if I'm lucky?
More information about the Digitalmars-d-learn
mailing list