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.

}
}
}
if( rider->isKindOf( KINDOF_HERO ) && m_heroUnitsContained > 0 )
Copy link

Choose a reason for hiding this comment

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

Make the m_heroUnitsContained > 0 an assert, because we do not expect this to be 0 here, right?

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.

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