When ManualObject slow in VS debugger

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
zone1
Gnoblar
Posts: 7
Joined: Wed Jan 29, 2014 4:09 am

When ManualObject slow in VS debugger

Post by zone1 »

This is not asking for help or reporting a problem, please read if ManualObject is slow for you in VS debugger too:

With very little changes to the original ManualObject code, it is easy to make it work much faster in the VS debugger. After measuring which parts of the code slow down too much I found that it happens in copyTempVertexToBuffer(), where STL iterators are accessed. (I don't get it why STL containers are used in core parts of a library where performance is essential, but that's beside the point.) The only change I made is allocating a small array of const VertexElement pointers. Instead of getting them many times for each vertex when calling position() from the STL container, I put them in the array, and use that for any further calls, until end(). This only happens in debug mode because VS takes extra caution in its STL containers and that causes very bad performance. In release code you can still use the original ManualObject (though not necessary).

With this I achieved 500fps when modifying a ManualObject with 4096 vertices 30 times per second, instead of the 2fps I got without this. I read that in previous posts people advised not to use the debugger for "measuring performance". That is a valid point, but most of the time you will be running your code in the debugger (until it is ready :P) and such slowdown is not really bearable.

Modifying the original code is easy if you download the source (you'll only need the OgreManualObject.cpp and .h), but for your convenience I have attached my version. For instructions see the top of the .h file. (You don't need to recompile Ogre, just include the header and use ManualObject2 in your project.)

01.02 UPDATE: I have added new functionality to the ManualObject. (See v2 attachment.) You can now replace part of the geometry if you call beginReplace instead of beginUpdate. Changing the position, color or texture coordinates of a vertex required rebuilding the whole geometry originally. With beginReplace, you can now really update them, instead of having to send the data of all vertices again. The code is not thoroughly tested yet, I haven't created subsections or checked whether changing texture coordinates really works or not, but as I find bugs I'll keep this updated. Please post if you find any problem with the code.

With this modification the number of vertices in the geometry no longer matter. Only the number of vertices replaced can influence the performance, but for the few vertices I needed to change so far there was no measurable slowdown at all.
Attachments
manualobjmodv2.zip
ManualObject with faster update when only part of the geometry is changing.
(20 KiB) Downloaded 22 times
manualobjmod.zip
modified ManualObject code
(18.04 KiB) Downloaded 25 times
Last edited by zone1 on Tue Feb 04, 2014 11:13 am, edited 2 times in total.
User avatar
mmixLinus
Silver Sponsor
Silver Sponsor
Posts: 199
Joined: Thu Apr 21, 2011 3:08 pm
Location: Lund, Sweden
x 12
Contact:

Re: When ManualObject slow in VS debugger

Post by mmixLinus »

Have you tried measuring the speed-up (if any) in Release builds?
Powered by Ogre3D:
MMiX.Me 3D - 3D Music Player
Galaxy Navigator 3D - 2 million stars (ESA's Gaia satellite)
YouTube|Facebook
User avatar
Zonder
Ogre Magi
Posts: 1168
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 73

Re: When ManualObject slow in VS debugger

Post by Zonder »

Making optimizations that help debugging is a good idea. Also as mmicLinus said did you measure the performance in release as well there is a chance it has also improved there you may need to be more demanding to notice though :)
There are 10 types of people in the world: Those who understand binary, and those who don't...
zone1
Gnoblar
Posts: 7
Joined: Wed Jan 29, 2014 4:09 am

Re: When ManualObject slow in VS debugger

Post by zone1 »

I just tested but there is no noticeable difference. I could produce around 31fps when moving vertices of a 192*192 grid with both the original and the modified version. (A "bit" more than 192*192, because I have a plane of triangles with distinct vertices for each quad, a separate grid of lines and same number of points as I wanted to make an editor where I can move the points of the grid. But for comparing performance it is almost the same whether it is 100*100 or 1000*1000 vertices.)

It would probably help a lot more if you wouldn't have to add each vertex again every time you change something. It doesn't seem difficult to modify ManualObject to do that though.
zone1
Gnoblar
Posts: 7
Joined: Wed Jan 29, 2014 4:09 am

Re: When ManualObject slow in VS debugger

Post by zone1 »

Bumping because I've updated the ManualObject modification. You can now move single vertices fast. Please read the first post.
Post Reply