Page MenuHomeWildfire Games

Avoid unnecessary updates from updateSettingsPanelPosition
ClosedPublic

Authored by nani on Dec 12 2018, 1:08 AM.

Details

Summary

updateSettingsPanelPosition is calling the engine on every tick even when is doing nothing. Fix it to make an early return when is doing nothing.

In my case the profiling gives an idle gui tick of 3.5 msec/frame and 0.9 msec/frame with fix.

Test Plan

Test that still works as intended and when the window resizes.

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

nani created this revision.Dec 12 2018, 1:08 AM
nani edited the summary of this revision. (Show Details)
lyv added a subscriber: lyv.Dec 12 2018, 6:37 AM

The same thing may also be the case in the ingame thing which slides down.

gui/gamesetup/gamesetup.js
1249 ↗(On Diff #7042)

If offset would always be a number, there is no need for triple equals no?
Can even do !offset too I suppose.

lyv added a comment.Dec 12 2018, 7:25 AM

The same thing may also be the case in the ingame thing which slides down.

Apparently, not.

function updateMenuPosition(dt)
{
	let menu = Engine.GetGUIObjectByName("menu");

	let maxOffset = g_IsMenuOpen ?
		END_MENU_POSITION - menu.size.bottom :
		menu.size.top - MENU_TOP;

	if (maxOffset <= 0)
		return;

	let offset = Math.min(MENU_SPEED * dt, maxOffset) * (g_IsMenuOpen ? +1 : -1);

	let size = menu.size;
	size.top += offset;
	size.bottom += offset;
	menu.size = size;
}
nani marked an inline comment as done.Dec 12 2018, 6:22 PM
nani added inline comments.
gui/gamesetup/gamesetup.js
1249 ↗(On Diff #7042)

I wrote it like this given that only the value 0 is meant to return true. I think that is shows better when this condition must be met and not some other similar although this might feel pedantic.

Silier added a subscriber: Silier.Dec 12 2018, 7:30 PM
Silier added inline comments.
gui/gamesetup/gamesetup.js
1249 ↗(On Diff #7042)

! offset is only true if offset is 0 or does not exist.

bb accepted this revision.Dec 26 2018, 9:20 PM
bb added a subscriber: bb.

And here the guy to blame :S, can't even put off the blame by saying it was copied from the main-menu or ingame menu...

offset always a number indeed. For me !offset suffices

Gui tick went down from 1.7ms to 0.4ms here, so absolutely worth changing this
The function is called twice and both cases could use this check, thus the position is correct

Change trivial => accept

This revision is now accepted and ready to land.Dec 26 2018, 9:20 PM
bb added a comment.Dec 26 2018, 9:37 PM

introduced in rP20945 (code got shuffled a bit afterwards)

bb requested changes to this revision.Dec 26 2018, 10:16 PM

While committing thought of the programming.json: @nani please put your nick and if you want name in there and upload in a new patch on the revision so you are credited

This revision now requires changes to proceed.Dec 26 2018, 10:16 PM
nani updated this revision to Diff 7073.Dec 26 2018, 11:28 PM
bb accepted this revision.Dec 26 2018, 11:30 PM

That should work

This revision is now accepted and ready to land.Dec 26 2018, 11:30 PM
This revision was automatically updated to reflect the committed changes.
Owners added a subscriber: Restricted Owners Package.Dec 26 2018, 11:35 PM
elexis added a subscriber: elexis.Dec 27 2018, 11:08 AM

can't even put off the blame by saying it was copied from the main-menu or ingame menu...

So the error is addressed in one of three places?

bb added a comment.Dec 27 2018, 12:51 PM

Even better: the error wasn't introduced there