Skip to content

Conversation

@bobtista
Copy link

@bobtista bobtista commented Nov 13, 2025

Summary

Optimizes Object::isHero() by caching hero count in containers instead of iterating through all contained objects on every call.

@bobtista bobtista force-pushed the bobtista/optimize-object-is-hero branch from bcbf169 to 386443b Compare November 13, 2025 04:18
@bobtista bobtista marked this pull request as ready for review December 15, 2025 17:10
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A number of questions.

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Performance Is a performance concern Gen Relates to Generals ZH Relates to Zero Hour labels Dec 15, 2025
@bobtista bobtista force-pushed the bobtista/optimize-object-is-hero branch from 4482d08 to df4e579 Compare December 15, 2025 22:44
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this will break Xfer Save and Load.

xfer->xferUnsignedInt( &m_stealthUnitsContained );

// hero units contained
xfer->xferUnsignedInt( &m_heroUnitsContained );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires Xfer version increment. And version history documentation. Also needs to be put behind RETAIL_COMPATIBLE_XFER_SAVE. See other code that does it.

In RETAIL_COMPATIBLE_XFER_SAVE, the count needs to be restored by iterating hero objects like the original code did it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. It's version 3 in MD and 2 in Generals now

}
if( rider->isKindOf( KINDOF_HERO ) )
{
DEBUG_ASSERTCRASH( m_heroUnitsContained > 0, ("Removing hero but hero count is 0") );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text is not quite accurate:

"OpenContain::removeFromContainViaIterator - Removing hero but hero count is %d", m_heroUnitsContained

Could add the same assert to stealth units above.

* Version Info:
* 1: Initial version */
* 1: Initial version
* 2: Added m_heroUnitsContained cached hero count (bobtista) */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TheSuperHackers @tweak Serialize hero units contained count

Do not use trailing (bobtista) because this is not part of our comment convention for authors.

Can put */ in new line.

{
m_heroUnitsContained = 0;
}
#endif
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole block looks overengineered. Can it be simplifed to just

	if (version >= 2)
	{
		xfer->xferUnsignedInt( &m_heroUnitsContained );
	}

?


}

#if RETAIL_COMPATIBLE_XFER_SAVE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use same technique as in #2024 for particle cannon to condition it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Performance Is a performance concern ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Object::isHero function is inefficient

2 participants