Interesting Memory Optimization

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Mar 19 17:17:15 PDT 2012


On Tue, Mar 20, 2012 at 12:55:29PM +1300, James Miller wrote:
> On 20 March 2012 01:33, Derek <ddparnell at bigpond.com> wrote:
> > Is the effort to do this really an issue with today's vast amounts
> > of RAM (virtual and real) available? How much memory are you
> > expecting to 'save'?
> >
> > And is RAM address alignment an issue here also? Currently most
> > literals are aligned on a 4 or 8-byte boundary but with this sort of
> > pooling, some literals will not be so aligned any more. That might
> > not be an issue but I'm just curious.
> 
> Gah, I hate this sentiment! It encourages lazy, poor design and
> practice simply because "RAM/CPU is cheap, dev time is expensive".
> Yes, RAM and CPU /are/ cheap, and dev time is expensive, but so is
> losing millions of dollars of revenue because your loading times on
> your app are 100ms too slow, and your conversion rate drops. This is
> the one thing that i hate about the Rails community, since it is their
> motto.

Not to mention that this kind of fallacious attitude causes people to
fail to realize the fact that the difference of 1 byte can make the
difference between an inner loop that accesses memory entirely within
the CPU cache, vs. one that causes a cache miss every iteration. The
difference in performance is HUGE.

(And no, I'm not suggesting we waste time optimizing bytes, but where
memory can be saved, it *should* be saved. Every little bit adds up; the
more compact your data structures, the more likely they will fit in the
cache and the less likely you'll cause cache misses in
performance-critical code.)


> Sites should be blazingly fast with today's computing power, but a
> ridiculous focus on "Developer productivity" has meant that no change
> has happened.

Exactly! In spite of the fact that CPU speed has increased on the order
of a millionfold since the old days, and in spite of the fact that
memory capacity has increased by several orders of magnitude, today's
software is STILL taking forever and two days just to load, and we STILL
run out of memory and thrash to swap on almost exactly the same tasks
that we did 10 years ago.

Where has all the performance boost drained into? Into bloated code with
over-complex designs that suck resources like a sponge due to lack of
concern with resource usage, that's what.


> I love it when D threads talk about whether or not the compiler does
> inlining, or loop unrolling, or whether it does, or should, use the
> correct instructions for the target. Not because I get off on talking
> about optimisation, but because it shows that there are still people
> care about squeezing every last instruction of performance, without
> compromising on productivity.

Exactly. Making the *compiler* produce better code is making a
difference where it matters. The compiler will be used by hundreds of
thousands of projects, so the slightest improvements carry over to all
of them *at zero cost to the application programmers*. It's a win-win
situation.


> Resources cost money, any saving of resources saves money.
[...]

+1.


T

-- 
English has the lovely word "defenestrate", meaning "to execute by
throwing someone out a window", or more recently "to remove Windows from
a computer and replace it with something useful". :-) -- John Cowan


More information about the Digitalmars-d mailing list