Skip to content

Optimization: XComPresentationLayerBase::UIUpdate() #76

@E3245

Description

@E3245

There is room for optimization in UIUpdate(). This function executes any time a new screen pops in the stack, is called by the tactical controller events (event ForceUIUpdate() and event PreRender(), and during the pre-render phase.

What UIUpdate() does is execute any delegates that were enlisted per tick, so UI elements such as arrows pointing on a units head, Flag manager, watching for Fullscreen changes, etc. all rely on continuous execution for its logic

At best, while the game is idle, UIUpdate() wouldn't be much of an issue, but worst case it can tank the FPS quite a bit while the delegates are processing:
image

Aggregate for 10 seconds of gameplay (no loading between GameReplicationInfo)
image

UIUpdate()/PreRender() can be pretty intense during normal gameplay for lower end processors.

The current code for reference:

	for( i=0; i<m_arrUIUpdateCallbacks.length; i++ )
	{
		dCallback = m_arrUIUpdateCallbacks[i];
		if (dCallback != none)
			dCallback();
	}

Most of this can be condensed down to using a foreach loop or a for loop without having to copy the delegate object.
foreach might be recommended because there's reason to believe that it can quickly process more iterations compared to for since we can forfeit the iterator:

https://forums.epicgames.com/udk/udk-development/udk-programming-and-unrealscript/267770-foreach-arrayvariable-vs-for-i-0-i-array-length-i?p=3063653#post3063653

So, using a foreach without an index would look like this:

	local delegate< UpdateCallback > dCallback;

	foreach m_arrUIUpdateCallbacks(dCallback)
	{
		dCallback();
	}

However, it's pretty much just conjecture. There's no telling if this will improve performance or not without some profiling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions