Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#1878 closed defect (fixed)

[PATCH] Gui tick is really slow when a unit is selected

Reported by: sbte Owned by: leper
Priority: Should Have Milestone: Alpha 14
Component: UI & Simulation Keywords: patch
Cc: Patch:


While playing, I noticed a lot of slowdown when a unit was selected and the mouse was hovering over an object. This was apparently caused by the cursor update. It repeatedly called GuiInterfaceCall (for GetSimulationState), which is really slow. I reduced this to one call per tick instead of up to 20, which speeds things up considerably.

Attachments (2)

Change History (12)

comment:1 by leper, 11 years ago

Owner: set to leper
Resolution: fixed
Status: newclosed

In 13336:

Don't call GetSimulationState too often. Patch by sbte. Fixes #1878.

comment:2 by leper, 11 years ago

Keywords: review removed

Thanks for the patch.

Another possible improvement (to reduce the number of calls to GetSimulationState even further) would be to call that only once for each tick and store it in a global and access that instead of calling it in 7 different places. (Where most of those don't change it and those that do (I think some do, but I'm not really certain) can be changed to operate on the cached simState)

comment:3 by Kieran P, 11 years ago

Yes, if threadsafe and serializable, I think we could try push data into a global scope that is accessible to multiple places, rather than passing it through like this.

Last edited 11 years ago by Kieran P (previous) (diff)

comment:4 by leper, 11 years ago

The GUI code runs in a different script context from the simulation (thus the need to invoke the Engine.GuiInterfaceCall method to get data), and I haven't heard of someone wanting to multithread the GUI (as in the GUI itself and not separating the GUI from the rest) and serialization isn't needed for the GUI code.

As the GUI context is separate using globals (when just defining them outside of functions, and not registering them as methods of the global object...) (that are actually just global to that script context) should help with reducing the number of calls to GUIInterface.

comment:5 by sbte, 11 years ago

leper, something like the attached patch maybe?

Edit: Moved updating of g_SimState to onSimulationUpdate

Last edited 11 years ago by sbte (previous) (diff)

comment:6 by fabio, 11 years ago

Resolution: fixed
Status: closedreopened

comment:7 by historic_bruno, 11 years ago

Keywords: review added

I seem to recall vaguely from years ago, there was some discussion of picking and choosing state to retrieve, since typically only a small amount of it is needed by a given UI function. That may be too much work for too little benefit and I may be misremembering anyway.

Does the latest patch preserve the original performance improvements? Just want to make sure we're not needlessly calling GetSimulationState every turn when it's not needed, or that whatever relative gain is worth it :)

comment:8 by sbte, 11 years ago

It improves the performance even more because of the line

-    var simState = Engine.GuiInterfaceCall("GetSimulationState");
+    g_SimState = Engine.GuiInterfaceCall("GetSimulationState");

This call would be made anyway. The other stuff is just reusing that call. It saves about 1 extra ms per turn for me.

comment:9 by leper, 11 years ago

Resolution: fixed
Status: reopenedclosed

In 13354:

Reduce duplicate GuiInterfaceCalls some more. Patch by sbte. Fixes #1878.

comment:10 by leper, 11 years ago

Keywords: review removed
Note: See TracTickets for help on using tickets.