Skip to content

Commit 539a62c

Browse files
committed
shrink table pools on gc
1 parent 63a7ab5 commit 539a62c

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

develop/ROADMAP.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
- We should have a way to not copy components on deferred spawn/clone
1212
- Having a light version of the gargabe collector can be useful for some use-cases
13-
- We can shrink the table pool tables on garbage collection if they are too large
1413
- Basic default component value as true looks awful, should we use something else?
1514

1615
## Known Issues

evolved.lua

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -702,21 +702,40 @@ local __table_pool_tag = {
702702
__count = 9,
703703
}
704704

705+
---@type table<evolved.table_pool_tag, integer>
706+
local __table_pool_reserve = {
707+
[__table_pool_tag.bytecode] = 16,
708+
[__table_pool_tag.chunk_list] = 16,
709+
[__table_pool_tag.system_list] = 16,
710+
[__table_pool_tag.each_state] = 16,
711+
[__table_pool_tag.execute_state] = 16,
712+
[__table_pool_tag.entity_list] = 16,
713+
[__table_pool_tag.fragment_set] = 16,
714+
[__table_pool_tag.fragment_list] = 16,
715+
[__table_pool_tag.component_table] = 16,
716+
}
717+
705718
---@class (exact) evolved.table_pool
706719
---@field package __size integer
707720
---@field package [integer] table
708721

709722
---@type table<evolved.table_pool_tag, evolved.table_pool>
710723
local __tagged_table_pools = (function()
711724
local table_pools = __lua_table_new(__table_pool_tag.__count)
712-
local table_pool_reserve = 16
713725

714-
for tag = 1, __table_pool_tag.__count do
726+
for table_pool_tag = 1, __table_pool_tag.__count do
727+
local table_pool_reserve = __table_pool_reserve[table_pool_tag]
728+
715729
---@type evolved.table_pool
716730
local table_pool = __lua_table_new(table_pool_reserve)
717-
for i = 1, table_pool_reserve do table_pool[i] = {} end
731+
732+
for table_pool_index = 1, table_pool_reserve do
733+
table_pool[table_pool_index] = {}
734+
end
735+
718736
table_pool.__size = table_pool_reserve
719-
table_pools[tag] = table_pool
737+
738+
table_pools[table_pool_tag] = table_pool
720739
end
721740

722741
return table_pools
@@ -6191,11 +6210,19 @@ function __evolved_collect_garbage()
61916210
end
61926211
end
61936212

6194-
for table_tag = 1, __table_pool_tag.__count do
6195-
local table_pool = __tagged_table_pools[table_tag]
6196-
for pool_index = 1, table_pool.__size do
6197-
table_pool[pool_index] = {}
6213+
for table_pool_tag = 1, __table_pool_tag.__count do
6214+
local table_pool_reserve = __table_pool_reserve[table_pool_tag]
6215+
6216+
---@type evolved.table_pool
6217+
local new_table_pool = __lua_table_new(table_pool_reserve)
6218+
6219+
for table_pool_index = 1, table_pool_reserve do
6220+
new_table_pool[table_pool_index] = {}
61986221
end
6222+
6223+
new_table_pool.__size = table_pool_reserve
6224+
6225+
__tagged_table_pools[table_pool_tag] = new_table_pool
61996226
end
62006227

62016228
do

0 commit comments

Comments
 (0)