Re: Memory manager: I'm porting SmartHeap to Delphi
From: Eric Grange (egrange_at_glscene.org)
Date: 01/30/04
- Next message: Eric Grange: "Re: Memory problem"
- Previous message: Dennis: "Re: Fastcode ComplexRegtDiv B&V 0.1"
- In reply to: Roberto Della Pasqua: "Re: Memory manager: I'm porting SmartHeap to Delphi"
- Next in thread: Dan Downs: "Re: Memory manager: I'm porting SmartHeap to Delphi"
- Reply: Dan Downs: "Re: Memory manager: I'm porting SmartHeap to Delphi"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 30 Jan 2004 09:56:27 +0100
Besides the late allocation issue Ignacio mentionned, there is also the
not-so-negligible issue of cache coherency.
For instance if you have to allocate memory for 100 records in an array
(only once), then perform some number crunching or sorting on those
records, there can be a huge performance difference depending on where
in the memory these records have been allocated: if they were tightly
fit together, they can all be available in CPU cache, which if they are
scattered over several megabytes, the CPU cache will be useless and
you'll be limited to RAM speed, whose clock speed is 5 to 10 times slower
than the CPU and has extra latencies of its own.
My very first attempts at a MM produced something that destroyed the default
manager in allocation/deallocation, but when used in a real world case,
actually degraded performance (because of that scattering). A good MM must
not only allocate/release fast, but also ensure that what is allocated is
"cache friendly" most of the time, otherwise you'll waste CPU cycles waiting
for read/write accesses to the RAM when you use the allocated memory.
Also, a common assumption in MM benchmarks is that allocations are random,
but in practice, they are *far* from being random. Each program has its own
specific patterns (which makes it hard to come with a "standard benchmark"),
but on all the proggies I've investigated, 80 to 90% of the memory allocations
were made for a dozen or so block sizes (typically the most-used-objects sizes,
the default string sizes, etc.), which were having quite "regular" lifecycles
(f.i. "gets reallocated twice on average, up to N kb then freed, rinse and repeat").
Being able to exploit these patterns automatically is in the "future plans",
some experiments with manual tweaking of the allocator showed that there are
fair boosts waiting to be harvested when the allocator is aware of those things
for all proggies whose data doesn't fit in the CPU cache.
Of course, these can also be achieved by optimizing the code, but that often
means making the code more complex and hard to maintain, while having it handled
by a memory allocator can be free, maintenance-wise.
Eric
- Next message: Eric Grange: "Re: Memory problem"
- Previous message: Dennis: "Re: Fastcode ComplexRegtDiv B&V 0.1"
- In reply to: Roberto Della Pasqua: "Re: Memory manager: I'm porting SmartHeap to Delphi"
- Next in thread: Dan Downs: "Re: Memory manager: I'm porting SmartHeap to Delphi"
- Reply: Dan Downs: "Re: Memory manager: I'm porting SmartHeap to Delphi"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|