ImageEngine/cortex — pull request #228 by ldmoser (2014-02-26 01:43:16+00:00)
Title: Reducing memory footprint in StreamIndexedIO

As scenes get heavier and deeper, the memory overhead of the data structures holding the hierarchy of the internal nodes in the StreamIndexedIO becomes significant. The structure is a tree of StreamIndexedIO::Node classes (104 bytes* each + contents of children map ) with DataNodes (56 bytes*) where data is saved.

With the following commits I've maintained the file format as is, and also binary compatibility (please review my third commit on that). And from my tests, performance was not affected. The memory consumption reduction varied in my tests from %20 to %70:
- Heavy asset (airBeam) 30% memory reduction
- Heavy asset with lots of tags 20% reduction
- Animated asset (droid) 48% reduction
- Linked scene (crowd) 70% reduction

The idea behind these changes were to have more Node classes that are specialized on particular cases and therefore don't need as many bytes. In order to do that, my first step was to change the StreamIndexedIO::Node class to behave as "private MemberData" class (kept the name for binary compatibility), that holds the pointer to the underlying Directory node and another pointer to the shared Index.

Then I've created this new class hierarchy:
NodeBase (16 bytes*)
|- DataNode ( 40 bytes* )
|- SmallDataNode ( 24 bytes* )
|- DirectoryNode (56 bytes* )
|- SubIndexNode ( 24 bytes* )

* sizes measures in 64bit machine.