Challenge: write a reference counted slice that works as much as possible like a built-in slice

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Nov 12 22:10:22 UTC 2021


On Fri, Nov 12, 2021 at 09:25:23PM +0000, russhy via Digitalmars-d wrote:
> On Thursday, 11 November 2021 at 09:15:54 UTC, Atila Neves wrote:
> 
> > > Who, using a SYSTEMS language, should not have a reason to care
> > > about their memory?
> > 
> > Me, ~99.9% of the time.
> > 
> 
> 
> This explains a lot and why D is stuck with a miserable GC

It depends on what the code is trying to do.  When I'm using D as a
superior shell scripting language, yeah I couldn't care less about the
intricacies of memory allocation.

If I'm writing performance sensitive code, though, which does happen
quite often, then I *do* care about minimizing allocations and/or
outright eliminating allocation from my inner loops.

It's about taking care of resource usage *where it matters*. There is no
point optimizing the heck out of a hello world program: that's just a
total waste of time. Save your efforts for when you're writing
performance critical code.

This is why I also say, why are people so hung up about the GC?  If your
inner loops have performance problems with the GC, then rewrite it as
@nogc, use malloc/free/whatever it takes to make it faster.  The rest of
the program can still use the GC -- there's no reason why I shouldn't
just allocate away when I'm rendering, say, the splash screen and
loading resource files on program startup, and let the GC clean up for
me. It's much faster to write and I don't waste time micro-optimizing
code that only runs once anyway.  I'd rather save my energy for when the
program starts doing real work and needs to get it done fast -- that's
when I pull out @nogc, GC.disable, malloc/free, etc..  Only the actual
bottlenecks (as measured by an actual profiler) need to do this; the
rest of the code that only runs once in a while don't matter, nobody
will care whether it uses GC or not.  Life is too short to fuss over
code that isn't even relevant to performance in the big picture.


T

-- 
The diminished 7th chord is the most flexible and fear-instilling chord. Use it often, use it unsparingly, to subdue your listeners into submission!


More information about the Digitalmars-d mailing list