Optimization suggestion

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
ChicChic
Gnoblar
Posts: 21
Joined: Tue Sep 05, 2017 10:19 am
x 6

Optimization suggestion

Post by ChicChic »

Hi,

I've made a test for my software consisting in adding about 120 point lights in my environment.
It appears that when loading the scene, hlms shader creation takes a looooooots of times just inside the Hlms::findBlockEnd function (about 76% of the whole loading time, see the screenshot)
Image

By looking at the code, it seems you just try to check if a string begin with a test string :

Code: Select all

size_t idx = subString.find( "end" );
if( idx == 0 )
or

Code: Select all

size_t idxBlock = subString.find( blockNames[i] );
if( idxBlock == 0 )
and if the main string is big (and it is because it's a hlms file) there is a lot of time wasted by looking after the beginning of the string.

What I suggest you is to add an SubStringRef::startWith function (or whatever name you want) to replace those test in the Hlms::findBlockEnd (and maybe in other places)

My test was made with the function :

Code: Select all

bool startWith( const char *stringCompare, size_t size) const
{
    return strncmp(mOriginal->c_str() + mStart, stringCompare, size) == 0;
}
Which seems right and reduced a lot the shader compile time for my test.

NB : Ok, my version of Ogre 2.1 is not up to date because I cannot update it. BUT the same advice apply in the actual branch of Ogre 2.1 as I checked...

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4260
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 831
Contact:

Re: Optimization suggestion

Post by dark_sylinc »

Could you upload a patch and state your commit hash? (or just point to a forked version of Ogre on github or bitbucket)
We are very interestered in these kind of optimizations.

Thanks!!!

ChicChic
Gnoblar
Posts: 21
Joined: Tue Sep 05, 2017 10:19 am
x 6

Re: Optimization suggestion

Post by ChicChic »

Ok sorry for the delai, I'm not a developer I'm a former robotician so I'm not friendly with those git tasks :?

Here is attached the patch file (renamed from .diff to .txt) made from the Ogre commit 272025b419cab7aac96f4575314fa8d1e975cc80 (master branch)

Is that what you want ??
Attachments
patch.txt
(4.59 KiB) Downloaded 26 times

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4260
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 831
Contact:

Re: Optimization suggestion

Post by dark_sylinc »

Thanks!

That was easy!

Well spotted. Took me 2 minutes staring at the screen to realize what was wrong

Added your code.
I changed "strncmp" for "strcmp" because calling strcmp( a, b, strlen( b ) ); beats the purpose of strncmp (the purpose of the 3rd parameter is to avoid buffer overflows in case the input is not null terminated, and for that strlen is pointless) That was a mistake.

Thanks for the speed up!
Cheers

Post Reply