Opened 11 years ago

Closed 10 years ago

#2027 closed enhancement (wontfix)

[PATCH] TextRenderer allocation and cache fix

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

Description

Currently the CGUI::DrawText and CTextRenderer is quite inefficient.

In CTextRenderer, for every [text+font] chunk, a temporary object and a copy of the string is made:

	struct SBatch
	{
		CMatrix3D transform;
		CColor color;
		shared_ptr<CFont> font;
		std::wstring text; // <--- bad!
	};

This results in a huge amount of temporary wstring objects that get deleted right after the small batch has been rendered. This is extremely inefficient.

In order to speed this up, two changes were made:

  • Removed wstring from SBatch, replaced with text_index and text_length
  • Added m_TextBuffer, m_VertexBuffer and m_IndexBuffer

Using this very basic buffering we can avoid a huge number of memory operations:

	struct SBatch
	{
		CMatrix3D transform;
		CColor color;
		CFont* font;
		int text_index;
		int text_length;
	};

In the actual CGUI::DrawText method CTextRenderer is just a temporary object, which is very bad, since the temporary font cache and buffers inside CTextRenderer is destroyed.

Fortunately the VFS cache system never releases the font handles. However if this is true, then why cache fonts EVERY DRAW CALL if you end up deleting them anyways? This makes no sense at all.

Solution: Since CTextRenderer is actually used a lot, the Singleton pattern makes sense here.

Attachments (1)

CTextRenderer_allocs.patch (15.9 KB ) - added by Jorma Rebane 11 years ago.
Initial release, waiting for review.

Download all attachments as: .zip

Change History (6)

by Jorma Rebane, 11 years ago

Attachment: CTextRenderer_allocs.patch added

Initial release, waiting for review.

comment:1 by Jorma Rebane, 11 years ago

Further remarks:

  • Breaks font hotloading - If we replace the current font system with FreeType fonts in the near future, will this really matter?

comment:2 by Jorma Rebane, 11 years ago

Keywords: performance added
Milestone: BacklogAlpha 14

comment:3 by alpha123, 11 years ago

I'd really like to get this in for Alpha 14. I tried it last night and it makes a really noticeable difference in scenario loading speed. I unfortunately don't have any hard numbers (well, I can load Gambia River in 36 seconds from a cold cache, but I don't know what it was without the patch) but apply it and it's hard not to notice.

Last edited 11 years ago by alpha123 (previous) (diff)

comment:4 by Kieran P, 11 years ago

Milestone: Alpha 14Alpha 15

comment:5 by historic_bruno, 10 years ago

Keywords: review removed
Milestone: Alpha 15
Resolution: wontfix
Status: newclosed

Closing these tickets as no further active development is expected. See Philip's megapatch-split git branch for an attempt at splitting megapatch into it's separate parts: http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/megapatch-split

Note: See TracTickets for help on using tickets.