Skip to content

Cache and reuse removed mobjs when spawning mobjs

Hanicef requested to merge Hanicef/SRB2:optimize-mobj-allocations into next

back when DOOM was originally written, the engine wasn't originally designed for creating and removing mobjs other than when maps were loaded in. while this worked fine back then, it also had the side effect that mobjs rarely disappeared, which lead to the iconic part of DOOM where bodies would remain for the entire duration of the map.

with SRB2, though, things have changed a bit. unlike DOOM, SRB2 is allocating mobjs en masse even on very simple levels. this is a potential issue in terms of performance, since each mobj that is spawned is a memory allocation in itself, and memory allocations are slow. so, to reduce this overhead, this patch will cache removed mobjs and reuse them later, to avoid unnecessary allocations. this might help with performance on maps that are allocating a lot of mobjs (the greatest offender i found was RVZ) and possibly even with some Lua scripts that isn't careful with mobj allocations.

Merge request reports