Your memory performance

Discussion about everything. New games, 3d math, development tips...
Dareltibus
Posts: 115
Joined: Mon May 17, 2010 7:42 am

Your memory performance

Post by Dareltibus »

how much times takes to you to execute this code? (both debug and release optimized)

Code: Select all

 
class Test{ // empty class
 
};
 
for(int i=0;i<10000000; i++) //ten millions allocations
    {
        Test * a = new Test;
        delete a;
    }
 
    return 0;
 
on debug it required 4.22 seconds (roughly 39.000 allocations per frame. assuming framerate of 60) (debugging symbols on)

on release it required 6.08 seconds (more time!very strange) (no debuggin symbols, -O2, stripping symbols)

after some testing seems that "stripping symbols in g++" increase allocation time even if this should speed up other things.

release build with only O2 to required 3.75 seconds (no debuggin, -O2, 44.000 allocations per frame)
optimizing for size (Os) required 3.7 seconds.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Your memory performance

Post by hendu »

Don't do that. You should remove all memory allocation from hot paths.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Your memory performance

Post by REDDemon »

hendu wrote:Don't do that. You should remove all memory allocation from hot paths.
he posted a virus? I'll not execute his code but at least explain why. (personally don't know anything about hot paths.)

If you are going to measure memory allocations speed you likely need microseconds timers, and anyway you can't profile memory like that.
A good allocator performance is measured in real cases (exactly where needed, since every allocator behaves differently)

Just to say, when I replace standard "new" in my game with specialized allocators I reduce allocation time from 2 to 30 times (this is not going to affect in significative manner framerate since there are not so many allocations every frame in my game so I left "new" not overloaded since is assumed to be more stable than custom allocators.).

Probably keeping a code like your will increase throughput of allocations but that's not a real case of allocation
so u should not assume your code as valid testing case (there are complex frameworks for this kind of tests just search on google/wikipedia. lot of material about memory
profiling).

and anyway.. 4 seconds are referred to wich CPU?, wich hardware you have? memory is affected by your internal PC architecture (bus speed, RAM speed, in some cases even HD speed since if your application is going to sleep for a while, Operative system is likely to temporary transfer your app on HD for later restore to free extra RAM for other processes). without knowing wich hardware you have, those numbers are mostly useless.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Your memory performance

Post by hybrid »

If you have a good allocator, there's almost no bus transaction taking place here. C++ does not initialize memories, so you only need to store the consumption of the memory area in your used mem list. This test case basically shows the performance of you libc you use.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Your memory performance

Post by REDDemon »

so that code is safe ? (hendu scared me to compile it even if at a first look seems normal code)..

and anyway yes BUS is very slow, but i measured it only once in a empiric way (don't know other ways to measure it):

http://irrlicht.sourceforge.net/forum/v ... =3&t=45360

and found that the time for computing a "cos(x)" was almost the same of fectching its value from RAM (at this point compute cos(X) without lookup tables is better, and supposed to be even faster on newer CPUs since my laptop is quite old.) the same test repetead on PCs at schools revelaed that my "20% faster cosine function" was in reality "35% slower". (but now that caches are several MBs maybe this result will change again?)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Your memory performance

Post by hendu »

Yes it's safe, but it makes no sense. It's common sense to not to allocate memory in a hot path like that.
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Your memory performance

Post by serengeor »

hendu wrote:Yes it's safe, but it makes no sense. It's common sense to not to allocate memory in a hot path like that.
what exactly are 'hot paths'?
Working on game: Marrbles (Currently stopped).
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Your memory performance

Post by hendu »

I thought it was a generally known term in the computersphere.

Hot path = code that is run often, such as every frame
Cold path = code run rarely
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Your memory performance

Post by serengeor »

Thanks, first time I heard of it :)
Working on game: Marrbles (Currently stopped).
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Your memory performance

Post by Granyte »

hendu wrote:Yes it's safe, but it makes no sense. It's common sense to not to allocate memory in a hot path like that.

so much for my galactic explorer and my planet generator all the alocation is done on the fly
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Your memory performance

Post by hendu »

You better rethink that if you want good performance, yes. Perhaps a pool of ready-to-use objects.
Dareltibus
Posts: 115
Joined: Mon May 17, 2010 7:42 am

Re: Your memory performance

Post by Dareltibus »

that's not hotpath. :) code is runned as benchmark and so, is a benchmark, the sense it makes is to measure "new" time. and since is made for that every other usage is of course senseless.. anyway I have 2.3 ghz cpu (AMD opteron)
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Your memory performance

Post by hendu »

Yes, it's a benchmark. But if you have proper code, you don't need to have good new performance, so it does point fingers ;)
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Your memory performance

Post by Granyte »

hendu wrote:You better rethink that if you want good performance, yes. Perhaps a pool of ready-to-use objects.

well performance is not bad because the allocation is hapening only when the user move around and then the generated object stay around until the user move again

also i cannot use a pool of pre generated object because in some region i have 52k stars rendered and in some other i have only 3k
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Your memory performance

Post by hybrid »

That's ok. Could be that in some regions you have up to 49k regions unused, but not unallocated. Also watch out for re-allocations, which are even worse, as they also copy the whole old region to a new place. You will really kill any performance if you use new too often.
Post Reply