Opened 11 years ago

Closed 10 years ago

#2006 closed enhancement (wontfix)

[PATCH] CModelDef slow/memory intensive load

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

Description

Check original Ticket: #1995

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.

Attachments (1)

CModelDef.patch (32.1 KB ) - added by Jorma Rebane 11 years ago.
Updated patch. Removed size_t 32/64-bit bug.

Download all attachments as: .zip

Change History (9)

comment:1 by Jorma Rebane, 11 years ago

Summary: CModelDef slow/memory intensive load[PATCH] CModelDef slow/memory intensive load

comment:2 by Jorma Rebane, 11 years ago

Keywords: patch review added; model performance memory load removed

comment:3 by Jorma Rebane, 11 years ago

Keywords: patch, review → patch review

comment:4 by Jorma Rebane, 11 years ago

Milestone: BacklogAlpha 14

comment:5 by Jorma Rebane, 11 years ago

Keywords: performance memory added

by Jorma Rebane, 11 years ago

Attachment: CModelDef.patch added

Updated patch. Removed size_t 32/64-bit bug.

comment:6 by wraitii, 11 years ago

Some comments, though generally this sounds good to me, and looking at the patch I see nothing outlandish:

  • 20 characters for the prop point name might be a bit too small. "horse_rider_projectile" is already above. I'd say 30/40 would be safe enough. Such a hard limitations also needs to be very explicit. I'm assuming it would throw an error with a longer name, and I think there should be an easy to understand error message
  • your patch as a "no newline at end of file" bit at the end of "ps/filelo.cpp"

(also, this is fairly random, but most patches use the "trunk" directory as the root, yours uses "Source").

However, I'm getting "EXC_BAD_ACCESS" crashes on many maps with it applied, apparently caused by "unpacker.UnpackRaw(vertices, sizeof(SModelVertex) * numVertices);" in ModelDef.cpp. Belgian Bog loads, but not other maps such as Acropolis.

Edit: is there a chance this could be caused by not cleaning my cache?

edit2: indeed it was. So forget about the mem bad acess, it works.

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

comment:7 by Kieran P, 11 years ago

Milestone: Alpha 14Alpha 15

comment:8 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.