#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: |
Description
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)
by , 11 years ago
Attachment: | 0003-Don-t-call-GetSimulationState-unnecessarily-often.patch added |
---|
comment:1 by , 11 years ago
Owner: | set to |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:2 by , 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 , 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.
comment:4 by , 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 , 11 years ago
leper, something like the attached patch maybe?
Edit: Moved updating of g_SimState to onSimulationUpdate
by , 11 years ago
Attachment: | 0002-Do-some-more-caching-in-the-gui.patch added |
---|
comment:6 by , 11 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:7 by , 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 , 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:10 by , 11 years ago
Keywords: | review removed |
---|
In 13336: