The numerous multi line "int" to "bool" performance warnings

Discussions About CyanWorlds.com Engine Client & Plugin
Post Reply
MustardJeep
Member
Posts: 54
Joined: Sat Dec 27, 2008 8:15 pm

The numerous multi line "int" to "bool" performance warnings

Post by MustardJeep »

Hi all,

Thought I would come out of lurk mode for a second to pose a question.

Has anyone patched the int to bool conversion performance warnings when compiling on vs2010?

Away from my home computer at the moment but I'll post one of the warnings when I'm home. The warning is fifteen to twenty lines and always starts "warning int yada yada yada convert to bool true false performance warning".

the problem I'm having is clicking it doesn't direct you to where the warning is being generated but instead off to what I'm assuming are subfunctions from the trouble maker.

the reason for the warning is fairly straight forward vs2005 evaluating a bool function with int values the compiler now recognizes the implied conversion. to warn the programmer of the conversion performance hit from branching the evaluation well there you go.

I just haven't been able to clear the awful things since they are so uninformative and I'm not exactly spending a ton of time on the problem yet.

ps I'm working with all warnings on as well as w_char as a built in on.

edit: here's the warning, and as you can see it is really uninformative as to where exactly the warning is really being caused compared to other warnings. I have the solution, it's rather well documented, I just havn't got a clue where to apply it. :lol:

13>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(163): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
13> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\utility(247) : see reference to function template instantiation 'std::_Pair_base<_Ty1,_Ty2>::_Pair_base<std::_Tree_iterator<_Mytree>&,_Ty>(_Other1,_Other2 &&)' being compiled
13> with
13> [
13> _Ty1=std::_Tree_iterator<std::_Tree_val<std::_Tmap_traits<std::wstring,hsStream *,std::less<std::wstring>,std::allocator<std::pair<const std::wstring,hsStream *>>,false>>>,
13> _Ty2=bool,
13> _Mytree=std::_Tree_val<std::_Tmap_traits<std::wstring,hsStream *,std::less<std::wstring>,std::allocator<std::pair<const std::wstring,hsStream *>>,false>>,
13> _Ty=int,
13> _Other1=std::_Tree_iterator<std::_Tree_val<std::_Tmap_traits<std::wstring,hsStream *,std::less<std::wstring>,std::allocator<std::pair<const std::wstring,hsStream *>>,false>>> &,
13> _Other2=int
13> ]
13> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xtree(988) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair<std::_Tree_iterator<_Mytree>&,int>(_Other1,_Other2 &&)' being compiled
13> with
13> [
13> _Ty1=std::_Tree_iterator<std::_Tree_val<std::_Tmap_traits<std::wstring,hsStream *,std::less<std::wstring>,std::allocator<std::pair<const std::wstring,hsStream *>>,false>>>,
13> _Ty2=bool,
13> _Mytree=std::_Tree_val<std::_Tmap_traits<std::wstring,hsStream *,std::less<std::wstring>,std::allocator<std::pair<const std::wstring,hsStream *>>,false>>,
13> _Other1=std::_Tree_iterator<std::_Tree_val<std::_Tmap_traits<std::wstring,hsStream
*,std::less<std::wstring>,std::allocator<std::pair<const std::wstring,hsStream *>>,false>>> &,
13> _Other2=int
13> ]
User avatar
Marten
Member
Posts: 180
Joined: Fri Dec 26, 2008 1:19 am

Re: The numerous multi line "int" to "bool" performance warn

Post by Marten »

That is really hard to parse without indentation! :lol:

Sometimes a warning is just a warning. The int/bool performance issue is one you'll find contention about if you do some searching. A good starting point for understanding this is the discussion here:
http://stackoverflow.com/questions/1847 ... er-to-bool

Quick take-aways from that discussion (for the example given):
* The necessary change to avoid the warning has the potential to cause more harm than good, due to possible typographical errors when typing !=, ==, and =.
* After making the recommended change to the code to avoid the warning, the resulting compiled output is the same, so for the compiler to insinuate there is a "performance" issue is groundless. It needs to be more discriminatory.

I know it's frustrating to have warnings spewing out. Warnings tickle the OCD in me, I want to fix fix fix, and I worry that I'll miss other important warnings amid all of the "bogus" ones, but I also worry that if I turn off the warning, I'll miss the one time it really meant something.

But you have to accept that you are smarter than the compiler, and maybe smarter than the person who put a warning into the compiler that maybe sometimes catches a real performance issue, but more frequently produces "false positives" to situations that can't be better optimized! I think you'll be at greater peace if you work around / disable the warning through compile options or #pragma settings, rather than try to "fix" what isn't necessarily broken just because VS2010 doesn't do a good job of discerning when the warning is truly appropriate.

Finally, I would really like to encourage you to work with the H'uru folks rather than on the OU branch of code. Collectively, they have already dealt with a lot of issues like this one (in fact, including this one). I'm sure they would appreciate having another person to work on improving the system, and I feel strongly that the community as a whole will benefit from more collaboration between developers as well.
The music is reversible, but time is not.
MustardJeep
Member
Posts: 54
Joined: Sat Dec 27, 2008 8:15 pm

Re: The numerous multi line "int" to "bool" performance warn

Post by MustardJeep »

I've actually read the stackoverflow thread you mention as well as the microsoft connect thread mentioned by Michal Burr months ago. Frankly I firmly believe the Microsoft Dev that implemented this warning was a bit full of himself in that reply. :lol:

If you don't mind me asking; Why do you feel "!=, == , =" could introduce typographical errors?

From my understanding of the issue and using the example it's basically asking the programmer to provide explicit bool syntax when the incoming variable being evaluated for a bool answer is declared int. It makes sense even if it is a rather pointless warning, but the answers people have given just leave me scratching my head. Int with only two values can be treated as bool but it doesn't change the fact that a better way to code it is passing the integer into a bool variable before evaluating since that makes the code easier to understand after the fact. :?: Do you understand :?: That paragraph kinda got away from me. :lol:

P.S. Thought cobbs and H'uru was dead? Deciding to work between the Guild of Writers dev group and the Open Uru Dev Group was a no brainer; I have a standing dislike for several of the major players in the GoW camp that date back to UU days. Plus while they do produce "improvements" at a rather frightening pace it's something of the same UU free for all that has been going on among themselves for years now. I want to work with Cyan's code not spend all my time trying to figure out theirs as it changes hourly. Besides while I have some rather detailed plans for "improvements" of my own I'm not there yet and it would be a waste of time to pretend I was. The restraint, dedication, and stable code base here are the reasons I want to work here not there. I can't test my changes yet and wouldn't think of passing them on to others as stable. So I ask questions every now and then and worry over them more with extra error code, their repository is a bit more pie in the face just from my very general look at it.
MustardJeep
Member
Posts: 54
Joined: Sat Dec 27, 2008 8:15 pm

Re: The numerous multi line "int" to "bool" performance warn

Post by MustardJeep »

Just posting an update...Only took three months solve.... :roll:

This bit of ridiculousness is generated by
hsTypes.h : line 132
hsTypes.h : line 103-108

It's the old school C bool hack; compiling on a C++ compiler with native bool types supported generates the warning.

I reset line 132 from int to bool, and commented out 103 to 108. A little bit of massaging here and there to get fit some sticky evaluations either bool or int and it all disappeared like it was never there.

My Reason for figuring ferreting this out?

If you define something int someone some where is going to use it as int even when it's meant to be bool.

I've got a clean compile with hsBool as type bool. WOOT go me!
Stucuk
Member
Posts: 36
Joined: Mon May 23, 2011 8:22 am

Re: The numerous multi line "int" to "bool" performance warn

Post by Stucuk »

MustardJeep wrote:I've got a clean compile with hsBool as type bool. WOOT go me!
You will have problems if you change hsBool to bool. Certain parts of the code use s->ReadSwap() so it will try and read a 1 byte value instead of the 4 byte value stored in the PRP files with your change.

plSound::plFadeParams::Read() is an example. fStopWhenDone and fFadeSoftVol are hsBools read as 4 byte values.
Image
-Stu
MustardJeep
Member
Posts: 54
Joined: Sat Dec 27, 2008 8:15 pm

Re: The numerous multi line "int" to "bool" performance warn

Post by MustardJeep »

Yes I know.......

Lucky for me Plasma is more a hobby then any dire necessity, but it does prove the point of what I said earlier. If you define something int someone some where is going to use it as int even when it's meant to be bool. Stupid programmers. :lol:

Plasma is without a doubt better off without hsBool since it straddles two languages, three separate types, and can be replaced transparently. Of course the main issue is that hsBool is used everywhere so replacement means scanning 5000 odd entries and trying to divine by context in the functions which type is needed. But that's why it's a hobby. :D

Besides I cheat.......Any variable not explicitly defined zero, one, true, or false I'm retyping as integer in my hsBool scratch copy.
Post Reply

Return to “CyanWorlds.com Engine - Client & Plugin”