diff --git a/docs/api/world.md b/docs/api/world.md index c75217e..c04b8c1 100755 --- a/docs/api/world.md +++ b/docs/api/world.md @@ -603,12 +603,26 @@ function World:exists( ## cleanup -Cleans up deleted entities and their associated data. This is automatically called by jecs, but can be called manually if needed. +Cleans up empty archetypes. ```luau function World:cleanup(): void ``` +:::info +It is recommended to profile the optimal interval you should cleanup because it varies completely from game to game. + +Here are a couple of reasons from Sander Mertens: + - some applications are memory constrained, so any wasted memory on empty + archetypes has to get cleaned up + - many archetypes can get created during game startup but aren't used later + on, so it would be wasteful to keep them around + - empty archetypes can slow queries down, especially if there are many more + empty ones than non-empty ones + - if the total number of component permutations (/relationships) is too + high, you have no choice but to periodically cleanup empty archetypes +::: + Example: ::: code-group diff --git a/jecs.luau b/jecs.luau index c6880f6..0fea236 100755 --- a/jecs.luau +++ b/jecs.luau @@ -74,7 +74,7 @@ type query = { filter_with: { i53 }, filter_without: { i53 }, next: () -> (i53, ...any), - world: World, + world: world, } export type observer = { @@ -1181,9 +1181,10 @@ local function query_archetypes(query: query) compatible_archetypes = {} query.compatible_archetypes = compatible_archetypes - local archetypes = query.world.archetypes + local world = query.world + local archetypes = world.archetypes - local component_index = query.world.component_index + local component_index = world.component_index local idr: componentrecord? local with = query.filter_with diff --git a/package.json b/package.json index b4805ac..611edcd 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rbxts/jecs", - "version": "0.9.0-rc.11", + "version": "0.9.0-rc.12", "description": "Stupidly fast Entity Component System", "main": "jecs.luau", "repository": { diff --git a/wally.toml b/wally.toml index 8ae400a..2a5ff37 100755 --- a/wally.toml +++ b/wally.toml @@ -1,6 +1,6 @@ [package] name = "ukendio/jecs" -version = "0.9.0-rc.11" +version = "0.9.0-rc.12" registry = "https://github.com/UpliftGames/wally-index" realm = "shared" license = "MIT"