P6: draw_world rescans all 64 actor slots once per layer -- 1024 refcount checks a frame
#26
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Source: TODO.md, "Performance" -> "The plan", item 6 (at
bbb7b8f)akgl_render_2d_draw_world(src/renderer.c:150-167) walks allAKGL_TILEMAP_MAX_LAYERSand, for each, rescans allAKGL_MAX_HEAP_ACTORslots-- 1024 refcount checks a frame for a one-layer map.
Half of this entry is already done and the issue is the other half. The
tilemap blit is guarded by
if ( i < akgl_gamemap->numlayers ), so a one-layermap draws one layer. The actor loop is not bounded by anything: it runs 16 times
regardless, and each pass reads every slot in the pool to find the ones on that
layer.
Fix: bound the outer walk by
akgl_gamemap->numlayers, and build theper-layer actor lists in one pool pass into static index arrays rather than
rescanning per layer.
Invisible at 60 fps under the software renderer; measurable on a 2 ms GPU frame.
Counting test, same shape as the tileset-scan issue.
Note the interaction: bounding the outer walk by
numlayersmakes the"actor on a layer past the last map layer is never drawn" defect sharper rather
than fixing it -- see the separate issue on
akgl_Actor::layerbeing unbounded.Files:
src/renderer.c:150-167Filed by Tachikoma (Claude Code, Opus 5, 1M context)