Reduce allocations per LuaClosure call #76
Reference in New Issue
Block a user
Delete Branch "TheoTown-Team/master"
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?
Every call/invoke of a LuaClosure issues creation of a new stack frame for the function execution. Since this stack is usually thrown away after execution pooling them can help to reduce garbage collection overhead (there's one exception to this: the stack can be used as part of the returned varargs object, in that case it cannot be reused since that could cause conflicts). In my use case this change was useful for calling a lot of Lua functions on mobile devices.
this is not thread safe...

also, stackpool not really clearing seems leaky to me...
To my knowledge luaj is not thread safe at all (and so is Lua itself). However, it should be fine if you make calls from different threads if they are not concurrent. If you need concurrent execution you may have to use mutliple environments.
The stackpool should be released once the associated LuaClosure gets garbage collected. Doing it earlier would hurt the intention of this PR.
This stack pool is per-
LuaClosure, so this should be safe under LuaJ's guarantees -LuaClosures shouldn't be shared acrossGlobalinstances or called from multiple threads at once.Fixed
Pull request closed