Memory Profiling

Obi includes its own memory profiler that can help you determine how much memory is used by your solver(s) and for what. You can access it in Unity's topbar menu, Window → Obi → Memory Profiler Once the profiler window opens, you'll see this:


Select any object with a ObiSolver component in the scene or any ObiActor(ObiRope, ObiCloth, ObiEmitter, ObiSoftbody, etc) for the profiler to show its data. Currently, the memory profiler has two modules: particles and constraints, each represented by a foldout in the profiler window. To the right of each foldout title, the total memory in use for that specific purpose is shown.


Particles module

Unfolding the particles module will present you with an interface similar to this:


At the very top you'll see a bar containing a collection of colored blocks, in a scrollview you can horizontally scroll and zoom in/out using the mouse wheel. The bar represents your solver's particle memory pool, and the number of blocks and their color depend on the specific actors currently inside your solver: each block represents the range of slots in the solver's memory in use by a specific actor. The text label at the center of each block shows the name of the actor and, between parentheses, the amount of particles used by that actor.

Actor types are color coded, and the color of each block shows the type of the actor it represents:

ObiRope:
Red
ObiRod:
Orange
ObiBone:
Purple
ObiCloth:
Blue
ObiSkinnedCloth:
Indigo
ObiTearableCloth:
Light blue
ObiSoftbody:
Yellow
ObiEmitter:
Green

Slots in use by inactive particles belonging to an actor are shown in a darker, less saturated version of these colors. In the following image, the right half of the ObiRope actor is a darker color to represent inactive particles in the rope - may be activated later, when the rope is torn or resized:


Free blocks appear in dark gray and have no text label in them. They are typically concentrated towards the rightmost end of the memory region. However, removing an actor can leave a free block in the middle of the memory region, this is referred to as fragmentation. Actors added later will be assigned the first free block where they can fit, any excess memory from the original block will form another, smaller block. When two free blocks end up adjacent to each other, they're coalesced into a single, larger free block. Coalescing reduces fragmentation as it increases the chance that free blocks can be used by other actors.


Below the bar you have a breakdown of the amount of actors of each type and the memory spent on particle data by type:


Under that, there's a breakdown of total amount of particle slots, how many are used by active particles, and how many are free.

At the very bottom of the particle profiler you'll find a table of all per-particle attributes registered in the solver. You can sort them by size and name using the dropdown at the upper right corner. Each row represents one attribute, with the following columns:

Attribute:
Name of the attribute, as registered.
Type:
Data type used by the attribute.
Bytes/prt:
Bytes per particle used by the attribute.
Count/cap:
Attribute count and capacity. Count is always less or equal than the capacity.
CPU:
RAM used by the attribute.
GPU:
VRAM used by the attribute.

Constraints module

Unfolding the constraints module will present you with an interface similar to this:


At the top you'll find a table of all constraints registered in the solver. Each row represents a constraint type, with the following columns:

Type:
Name of the constrain type, as registered.
WI size:
Number of slots per work item for this constraint type.
Work items:
Amount of work items currently allocated for this constraint type.
Used/Active:
Amount of used and active constraint slots for this type.
pIdx:
Total amount of particle indices used by this constraint type: each index references one particle in the solver.
Orphaned:
Total amount of particle indices not referenced by any constraint and not reachable via the constraint allocator.
CPU:
RAM used by this constraint type.
GPU:
VRAM used by this constraint type.

Click any of the table rows to select that particular constraint type and get detailed information about it. Upon selecting a constraint type, you'll get 3 bars containing collections of colored blocks that you can horizontally scroll and zoom in/out. From top to bottom, these represent particle indices, work items, and work item blocks.

Actor types are color coded, and the color of each block shows the type of the actor it represents:

ObiRope:
Red
ObiRod:
Orange
ObiBone:
Purple
ObiCloth:
Blue
ObiSkinnedCloth:
Indigo
ObiTearableCloth:
Light blue
ObiSoftbody:
Yellow
ObiEmitter:
Green

To make sense of this data, it's necessary to understand a bit more about how Obi constraints are stored in memory: each constraint in Obi affects multiple particles. Some constraints affect a fixed amount of particles, like distance constraints that affect 2 particles each, or bend constraints that affect 3, some others like shape matching constraints affect a variable amount of particles. So each constraint allocates a set of particle indices to store references to the particles it affects. The memory used to store these indices is what the topmost bar represents.

Individual constraints are then grouped into work items in a way that maximizes the amount of particles shared by all constraints in a work item. Work items are the smallest unit of memory that can be allocated for constraints, which means some work items may have empty slots. For instance, if your actor only has 3 constraints but work item size is 8, you'll end up with a single work item with 3 used and 5 empty slots. An used slot may contain an active constraint (evaluated by the solver) or an inactive one (the constraint is temporarily skipped by the solver). If all used slots in a work item contain inactive constraints, the work item itself is flagged inactive and not even considered by the solver. The memory used to store work items is what the middle bar represents.

Constraints may belong to an actor - structural constraints like distance, bend, or shape matching - or may be individual constraints associated to no actor in particular - like stitch constraints or pin constraints. Constraints belonging to an actor are always stored contiguous to each other, forming a block of work items. This is what the bottom bar represents.

Free blocks appear are dark gray and have no text label in them. They are typically concentrated towards the rightmost end of the memory region. However, removing an actor will leave a free block in the middle of the memory region. This is referred to as fragmentation. Actors added later will be assigned the first free block where they can fit, any excess memory from the original block will form another, smaller block. When two free blocks end up adjacent to each other, they're coalesced into a single, larger free block. Coalescing reduces fragmentation as it increases the chance that free blocks can be used by other actors.

Individual blocks appear in light gray, they represent constraints that aren't associated to any actor. For instance, pin or stitch constraints.

Orphaned and overflowed particle indices appear in magenta and bright red. These represent areas containing corrupted memory and shouldn't normally appear. If they do, please contact us and share a screenshot of your memory profiler for us to investigate.

Under the bars, you'll see various statistics about the currently selected constraint type: numer of work items, work item size, active, free, and reserved constraint slots, and total amount of particle indices.

At the very bottom you'll see a list of data buffers used by the current constraint type. You can sort them by size and name using the dropdown at the upper right corner. Each row represents one buffer, with the following columns:

Name:
Name of the data buffer.
Granularity:
What does each entry in the buffer belong to: one entry per constraint, per particle index, per solver particle, per work item, per batch or custom.
Type:
Data type contained in the buffer.
Stride:
Size in bytes of the type.
Count/cap:
Buffer count and capacity. Count is always less or equal than the capacity.
CPU:
RAM used by this data buffer.
GPU:
VRAM used by this data buffer. Note only the GPU copies of the buffers declared by the constraint container are accounted for, buffers used by the backend implementation do not appear here.