World Statistics
Arche only exposes the API required for actual use. Therefore, internals like the number of archetypes, memory used to store components etc. are not directly accessible.
However, it might sometimes be useful to have access to such metrics, for example in order to judge effects of different ways of implementing something. Otherwise, users would have to rely on logic reasoning and sufficient understanding of Arche to derive these numbers.
For that sake, Arche provides statistics about its internals, prepared in a compact and digestible form.
Accessing statistics
All internal statistics can be accessed via
ecs.World.Stats
,
which returns a
*stats.World
.
This, in turn, contains the other stats types described below.
All these types have a method String()
to bring them into a compact, human-readable form.
1world := ecs.NewWorld()
2
3builder := generic.NewMap2[Position, Heading](&world)
4builder.NewBatch(100)
5
6stats := world.Stats()
7fmt.Println(stats)
Which prints:
1World -- Components: 2, Nodes: 3, Filters: 0, Memory: 7.0 kB, Locked: false
2 Components: Position, Heading
3Entities -- Used: 100, Recycled: 0, Total: 100, Capacity: 128
4Node -- Components: 0, Entities: 0, Capacity: 1, Memory: 0.0 kB, Per entity: 0 B
5 Components:
6Node -- Components: 2, Entities: 100, Capacity: 128, Memory: 4.0 kB, Per entity: 24 B
7 Components: Position, Heading
World stats
stats.World
provides world information like a list of all component types
and the total memory reserved for entities and components.
Further, it contains
stats.Entities
and
a
stats.Node
for each active archetype node.
Entity stats
stats.Entities
contains information about the entity pool,
live capacity, alive entities and available entities for recycling.
Node stats
stats.Node
provides information about an archetype node, like its components, memory in total and per entity,
and more state information.
Further, it contains a
stats.Archetype
for each archetype.
Archetype stats
stats.Archetype
contains size, capacity and memory information for an archetype.