#1984 closed enhancement (fixed)
[PATCH READY] Save GUI Sprites and Images in vectors / maps as pointers instead of objects
Reported by: | Jonas Platte | Owned by: | JoshuaJB |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 16 |
Component: | UI & Simulation | Keywords: | memory performance |
Cc: | Patch: |
Description
When inserting into lists or vectors, the data is often reallocated and moved. The m_Sprites map in CGUI and the m_Images vector in CGUISprite save objects instead of pointers so there are many unnecessary construction and destruction operations, specially during startup.
This patch makes CGUI use std::map<CStr, CGUISprite*> instead of std::map<CStr, CGUISprite> and CGUISprite use std::vector<SGUIImage*> instead of std::vector<SGUIImage>.
Attachments (1)
Change History (18)
comment:1 by , 11 years ago
Keywords: | patch review added |
---|---|
Milestone: | Backlog → Alpha 15 |
comment:2 by , 11 years ago
comment:4 by , 11 years ago
Update: Use NONCOPYABLE macro.
I hope this is the last Update for today. Sorry for all the mail updates I caused.
comment:5 by , 11 years ago
You do want to clean that diff before you send it here. The config part and the lua script part shouldn't be in it. (it can be manually deleted from the diff text before uploading).
by , 11 years ago
Attachment: | gui_sprite_patch.diff added |
---|
comment:6 by , 11 years ago
Sorry I forgot to only make a diff of source that time. And is there a way to delete that double attachment?
comment:7 by , 11 years ago
Cc: | added |
---|
comment:8 by , 11 years ago
Keywords: | reviewed added; review removed |
---|
Hey, finally found some time to review your patch.
At first glance, there doesn't appear to be anything wrong with the patch and in my opinion it's the right way to go.
I'll mark your patch as "reviewed" and it will be committed as soon as A14 has been released and the feature lock is lifted.
comment:9 by , 11 years ago
Summary: | [PATCH] Save GUI Sprites and Images in vectors / maps as pointers instead of objects → [PATCH READY] Save GUI Sprites and Images in vectors / maps as pointers instead of objects |
---|
comment:10 by , 10 years ago
Cc: | removed |
---|---|
Keywords: | reviewed removed |
comment:11 by , 10 years ago
Keywords: | review memory performance added |
---|---|
Milestone: | Alpha 15 → Alpha 16 |
Besides checking for correctness/conventions, this patch will need to be profiled before and after applying to confirm a measurable difference in performance and/or allocations.
comment:12 by , 10 years ago
I already benchmarked this, though I did not document it. This is what I can recall:
On startup, there were about 650 objects which were created through passing other objects by value before the patch. With the patch, there is no more copying.
Although that sounded much to me at first, it seems those objects hold not much data (some of it was pointer data, so not everything was copied) and the startup timer that is shown on the command line by default indicated a very low to no impact on the startup time.
After startup, there are much less Sprites and Images created, so the patch will probably not make the game any faster – at least that was the case for the environment I tested it in, I do not know what has changed since then.
Overall this will definitely not slow down the game and it is just better style, but do not expect it to get the game starting or running noticeably faster.
comment:13 by , 10 years ago
Keywords: | reviewed added; review removed |
---|
I reviewed the patch and I really don't see a problem, it's better style and is the direction the UI code should be moving towards. I'll commit this when I have some time if there are no objections.
comment:15 by , 10 years ago
Component: | Core engine → UI & Simulation |
---|---|
Keywords: | patch reviewed removed |
Update: Made SGUIImage and CGUISprite non-copyable because they now own the data their members point to (delete it in the constructor)