Opened 11 years ago

Last modified 11 years ago

#1995 closed enhancement

[PERFORMANCE] Memory allocation reduction — at Version 14

Reported by: Jorma Rebane Owned by: Jorma Rebane
Priority: Must Have Milestone: Alpha 15
Component: Core engine Keywords: patch performance memory
Cc: Patch:

Description (last modified by Jorma Rebane)

Using MTuner data from a short run of the game, we can drastically improve 0 A.D. core engine performance, by reducing the number of allocations in the detected hotspots.

For more information, check the Memory Performance thread on the forums: http://www.wildfiregames.com/forum/index.php?showtopic=17310&st=20#entry270448

Sub-tickets: modeldef.cpp: #2006 parser.cpp: #2005 guimanager.cpp: #2007 textrenderer.cpp: #2027 shaderdefines.cpp: #2029

<progress>, <memblock>, <total memops>, <stacktrace>
(V),		size 4, 	count 61320, 	modeldef.cpp:300
(V),		size 8, 	count 61320, 	modeldef.cpp:301
(V),		size 48,	count 42028, 	parser.cpp:246
(V),		size 36,	count 40866, 	guimanager.cpp:273 & 265
(V),		size 8, 	count 32749, 	modeldef.cpp:241
(V),		size 32,	count 27638, 	textrenderer.cpp:136
(V),		size 8,		count 21952, 	cgui.cpp:986
(V),		size 16,	count 21952, 	textrenderer.cpp:77
(V),		size 16, 	count 21952, 	shaderdefines.cpp:135
(V),		size 48,	count 21952, 	cgui.cpp:954
(V),		size 12,	count 20688, 	modelrenderer.cpp:635
(V),		size 112,	count 17325, 	guirenderer.cpp:388
( ),		size 108,	count 16896,	patchrdata.cpp:173
(V),		size 8,		count 14852, 	shaderdefines.cpp:116
(x),		size 48,	count 14154, 	font.cpp:33
( ),		size 36,	count 13230, 	patchrdata.cpp:1025
(V),		size 48,	count 12008, 	parser.cpp:981
( ),		size 24, 	count 9783, 	patchrdata.cpp:1025
(V),		size 8,		count 9645, 	modelrenderer.cpp:433
(V),		size 8,		count 8935, 	modelrenderer.cpp:698
( ),		size 48,	count 8265, 	cgui.cpp:916
(V),		size 48,	count 8144, 	parser.cpp:933
( ),		size 93,	count 7806, 	guitext.cpp:266
( ),		size 132, 	count 7806, 	cgui.cpp:689
( ),		size 132,	count 7806, 	cgui.cpp:800 & 855
(V),		size 12,	count 7072, 	modelrenderer.cpp:636
(V),		,		,		textrenderer.cpp:77
(V),		,		,		textrenderer.cpp:179
( ),		,		,		patchrdata.cpp:1052
( ),		,		,		guitext.cpp:210
( ),		,		,		terraintextureentry.h:75
( ),		,		,		patchrdata.cpp:192
( ),		,		,		cgui.cpp:675
( ),		,		,		texturemanager.cpp:150
( ),		,		,		texturemanager.cpp:153
( ),		,		,		texturemanager.cpp:511
( ),		,		,		texturemanager.h:136
(V),		,		,		parser.cpp:639
( ),		,		,		componentmanager.cpp:620

Change History (14)

comment:1 by Jorma Rebane, 11 years ago

Description: modified (diff)

comment:2 by Jorma Rebane, 11 years ago

Description: modified (diff)

comment:3 by Jorma Rebane, 11 years ago

Description: modified (diff)

CModelDef fixes uploaded. This patch addresses two problems: 1) CModelDef loading performance

In order to make loading faster, had to change the format of cached binary model data. The new model cache files take a tiny bit more disk space, but in return they load several times faster and the loaded data takes less memory.

2) Complex dynamic objects in structs

One of the main perf hitters was a per-vertex (yes, per each vertex!) std::vector<float> for multiple UV's. This was replaced with 2x CVector2D UV0 & UV1. Another one was an std::string for model prop points, which was replaced with a fixed size buffer m_Name[20] and with an additional m_NameLength.

The result: much better memory performance and usage for model loading.

In order for this to work, I had to change the version of the PMD (binary model cache) format to 4 and change the way models are saved to PMD. This may invalidate any existing model cache. Backwards compatibility for versions 1, 2, 3 is there.

Last edited 11 years ago by Jorma Rebane (previous) (diff)

comment:4 by Jorma Rebane, 11 years ago

Description: modified (diff)

CParser fix finished. Check ticket: #2005

Last edited 11 years ago by Jorma Rebane (previous) (diff)

comment:5 by Jorma Rebane, 11 years ago

Description: modified (diff)

comment:6 by Jorma Rebane, 11 years ago

Description: modified (diff)
Summary: [Performance] Memory allocation reduction[PERFORMANCE] Memory allocation reduction

comment:7 by Jorma Rebane, 11 years ago

Description: modified (diff)

comment:8 by Jorma Rebane, 11 years ago

Keywords: patch review added
Milestone: BacklogAlpha 14

comment:9 by Jorma Rebane, 11 years ago

Description: modified (diff)

Updated: CTextRenderer patch added.

comment:10 by Jorma Rebane, 11 years ago

Description: modified (diff)

CTextRenderer patch also fixes cgui.cpp:986

comment:11 by Jorma Rebane, 11 years ago

Description: modified (diff)

comment:12 by Jorma Rebane, 11 years ago

Description: modified (diff)

Added ShaderDefines fix. Check ticket #2029

comment:13 by Jorma Rebane, 11 years ago

Description: modified (diff)

comment:14 by Jorma Rebane, 11 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.