where to post source comments

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

where to post source comments

Post by Insomniacp »

Hey,
So I have started going through the irrlicht source code and I have come across some things I have been able to find some things that could be optimized such as the following from CAnimatedMeshSceneNode.cpp (updated trunk from https://irrlicht.svn.sourceforge.net/sv ... icht/trunk ) which should be the most up to date correct?

Code: Select all

//---slow---
			for (u32 n=0;n<JointChildSceneNodes.size();++n)
could/should be

Code: Select all

//---slow---
u32 size = JointChildSceneNodes.size();
			for (u32 n=0;n<size;++n)
since JointChildSceneNodes.size() would get called every iteration it would slow down the for loop, if you put it in a variable it just gets accessed which is faster. Though you probably know that already I figured while I went through the code learning it more I could mark all of the things that I find that could be optimized or done better and post them somewhere... but alas I know not where they should go... As they aren't bugs I don't think I should post them there. Anyway I look forward to taking a good look at the source code :)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

The forum here is ok for discussions about the engine code. But be careful before you say something is slow until you profiled it or looked at the resulting machine code (compiled with optimization). Guessing is nearly always wrong.

I don't know about this one - size() is inline so the compiler will probably optimize the function call away. So you mainly add another assignment here with your solution. Maybe your additional assignment would allow the compiler to use another optimization because the loop as now a guaranteed fixed size. But well - find it out if you want - use a few compilers to figure out what they produce.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Post by greenya »

Here definition of array::size()

Code: Select all

u32 size() const
{
      return used;
}
So probably when you writing:

Code: Select all

for (u32 n=0;n<JointChildSceneNodes.size();++n)
compiler optimizes it to:

Code: Select all

for (u32 n=0;n<JointChildSceneNodes.used;++n)
you cannot use "used" in code by yourself (since its private), but compiler can use it for optimization.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

yeah, I will check to see if its faster or not but I figured I would get a spot to post my findings. That was just an example that I found at the first function I looked at, it was labeled slow already by someone else who commented it.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Insomniacp wrote: it was labeled slow already by someone else who commented it.
but only bc updating the absolute position of all children is slow and should be an option just like stated there.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

I remember this coming up before. If I remember right, the results of testing showed that it was slower in debug mode, but in release mode the optimizer made it come out the exact same speed.
Post Reply