Opened 13 years ago

Last modified 21 months ago

#885 closed enhancement

GUI code improvement — at Initial Version

Reported by: kromxp Owned by:
Priority: Nice to Have Milestone: Alpha 23
Component: Core engine Keywords:
Cc: Patch:

Description

--The problem--

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.

--Suggested solution--

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.

Change History (1)

by kromxp, 13 years ago

Attachment: faster-0ad-gui.patch added

gui patch

Note: See TracTickets for help on using tickets.