This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Performance Issue - Solution found;searching for Explanation


Performance Issue - Solution found;searching for Explanation

Postby drgoldie » Sep 19, 2007 @ 9:18pm

Today I ran into the most weird performance problem/bug I ever encountered:

My program conists of 3 main blocks of code. At the end of block 1 there is a function that does some math (pure integer, nothing special). For some reason that code turned out to be 10 times slower if I execute the other two main blocks of code afterwards. Without executing those other two block (after block 1 finished...) it runs at top performance.

Lots of debugging, benchmarking and testing reveiled that the problem was related to using an STL vector object (on the stack and only in that one function). I changed my code to use an old-school static array and the problem was gone. Yet, simply introducing the vector again into that function and just adding three integers brings the performance down again.

I solved by problem by not using a vector in that method, but I'd really be happy if somebody could explain what's going on here - and how this is connected to the other two blocks of code which have nothing to do with that vector...

Daniel

P.S.: All done in C++ using VS2005, SP1 and the Qt/Boost hotfix.


P.P.S.: If this was Java I'd say the garbage collector is malfunctioning, but in C++...?
drgoldie
pm Member
 
Posts: 330
Joined: Jan 10, 2003 @ 10:46am
Location: Vienna


Re: Performance Issue - Solution found;searching for Explana

Postby hm » Sep 19, 2007 @ 10:15pm

User avatar
hm
pm Member
 
Posts: 201
Joined: Dec 28, 2003 @ 8:47pm
Location: Seattle, WA


Postby drgoldie » Sep 19, 2007 @ 10:16pm

drgoldie
pm Member
 
Posts: 330
Joined: Jan 10, 2003 @ 10:46am
Location: Vienna


Postby hm » Sep 20, 2007 @ 5:24am

User avatar
hm
pm Member
 
Posts: 201
Joined: Dec 28, 2003 @ 8:47pm
Location: Seattle, WA


Postby mm40 » Sep 24, 2007 @ 3:04pm

So in the function you are doing vector.push_back 3 times?

If so the reason it is slowing it down so much is because of memory allocation. I have seen this many times in my games, I have moved to use a custom vector class which gives me more control over memory allocation and deallocation, without that my games would run at 1fps. Basically I allocate/reserve all memory up front or in huge chunks. Allocating 1MB vs. 1byte takes almost the same time on the PPC. So when you do 3 push_backs that is allocating memory 3 times, which is very slow compared to some integer math.

What I do if I need memory on the fly is call vector.reserve(100) giving me space for 100 items, then the 3 calls to push_back only have the cost of 1 memory allocation, I don't even remember if you can do this std::vector as I've been using my custom vector for so long.
User avatar
mm40
pm Member
 
Posts: 135
Joined: Feb 21, 2003 @ 9:11pm


Postby drgoldie » Sep 24, 2007 @ 3:12pm

I understand what you are explaining, but I think it still should not react that intensively.

There is lots of dynamic memory handling in my code. Yet performance does not drop that much. This is not code that is called 10.000 times per frame. It is called only three times for a frame...

Daniel
drgoldie
pm Member
 
Posts: 330
Joined: Jan 10, 2003 @ 10:46am
Location: Vienna


Postby mm40 » Sep 24, 2007 @ 3:54pm

What is the performance difference are you noticing, what are the timings?
User avatar
mm40
pm Member
 
Posts: 135
Joined: Feb 21, 2003 @ 9:11pm


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron