Page 1 of 1

Optimization suggestion

Posted: Wed Jan 29, 2020 3:04 pm
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...

Re: Optimization suggestion

Posted: Wed Jan 29, 2020 3:52 pm
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!!!

Re: Optimization suggestion

Posted: Thu Jan 30, 2020 10:43 am
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 ??

Re: Optimization suggestion

Posted: Thu Jan 30, 2020 4:43 pm
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