The game own programming performance documentation goes into detail of how they wish us lua modders to improve performance by for example avoiding garbage collection. It explains that its a good measure to reuse objects be they of any kind and it makes an example on vec3() Code: local my_vec = vec3() local function myFunc() my_vec:set(0, 0, 0) -- this :set() method, instead of vec3(0, 0, 0) end and tells about garbage free alternatives Code: local veh_pos = vec3() local function myFunc() local vehicle = getPlayerVehicle(0) veh_pos:set(vehicle:getPositionXYZ()) -- zero garbage. XYZ returns a tuple that we write directly into the vec object that we defined in the scope of the entire file end I have been experimenting with gc happy code over the past months and was for my very self able to write zero garbage collection mods while maintaining readability of them. However there are a few things that i personally have to use alot that id wish to also have XYZ alternatives. In GE Lua - getPlayerVehicle(0):getCenterXYZ() Currently the only method to get the true center of the vehicle is by reading the bounding box and then from that the center. And while the getCenter operation has a XYZ alternate, the bounding box object itself is garbage. So id wish of a method that can return the center pos directly without retrieving the bounding box first- getPlayerVehicle(0):getExtendsXYZ() Same issue as with the :getCenterXY(). The bounding box must be retrieved first which causes garbage In VE Lua - obj:getCenterPositionXYZ() There is no XYZ alternate to :getCenterPosition() - obj:getNodePositionXYZ() There is no XYZ alternate to :getNodePosition() Thats sums it up. Others may have more ideas. PS. The docs could provide some samples of how to write garbage avoiding code, because i think its easy to make such code unreadable and unfavorable. I dont mind writing that doc. While i cant show the code of this yet, this here for example is zero garbage code
I have a big tech debit task of converting all my var = vec3() to :set() Also to use the XYZ versions. Thanks for the call out.
Me too, my mods pre this knowledge all suffer that. One thing i learned is to test it out in small, to find something that fits your coding flow and then to test it with gcprobe and the analyzer. I personally for example cant get warm with the games vec3() implementation, i find that the code becomes messy. Take this as an example. So i for myself made my own to solve that issue for me