Ticket #885 (new enhancement)
[PATCH] GUI code improvement
|Reported by:||kromxp||Owned by:||philip|
|Priority:||Nice to Have||Milestone:||Backlog|
The gui code (source/gui) uses many variables linked with js and the xml reader (I suppose), these variables are added using AddSetting(type, stringy_name). Later many of this variables are getted/setted using GUI<type>::SetSetting and GUI<type>::GetSetting
These getters and setters was searching on a std::map each time. Using a profiler (gprof) on my computer, these appears on the top, taking > 7% of the running time. Running the game for around 1 minute would generate ~20 millions calls to these functions, this is because many of this calls was done each loop when redrawing the screen.
When creating the new types, the old code using a dynamically allocated variable. With the new changes it can use member variables of the calling class.
Then, because the values now are stored in member variables, almost all the parts that was using the old code to find the values now just get the value of the member variable which is an order of magnitude faster than searching a map.
In case the variables are "Setted", care has been taken to generate the set events so other parts of the code might receive it, just like it was done before.
After applying the changes, the numbers of calls to std::map::find reduced drastically (some thousands after couple of minutes), and those are mostly coming from js code (which should be the correct way in this case). Now takes less than 0.1% of the running time.
- Keywords review added
- Summary changed from GUI code improvement to [PATCH] GUI code improvement
- Owner set to kromxp
- Priority changed from Should Have to Nice to Have
- Keywords patch added; patch, review removed
- Milestone changed from Alpha 8 to Backlog