Reduce allocations per LuaClosure call #76

Closed
LobbyDivinus wants to merge 3 commits from TheoTown-Team/master into master
LobbyDivinus commented 2020-09-01 08:42:14 +00:00 (Migrated from github.com)

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.

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.
wagyourtail commented 2023-11-05 14:38:21 +00:00 (Migrated from github.com)

this is not thread safe...
image
also, stackpool not really clearing seems leaky to me...

this is not thread safe... ![image](https://github.com/luaj/luaj/assets/6234704/bce5fe99-6aa7-43f6-ac0d-49cb20bb2596) also, stackpool not really clearing seems leaky to me...
LobbyDivinus commented 2023-11-06 09:00:15 +00:00 (Migrated from github.com)

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.

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.
SquidDev commented 2023-11-06 09:56:48 +00:00 (Migrated from github.com)

This stack pool is per-LuaClosure, so this should be safe under LuaJ's guarantees - LuaClosures shouldn't be shared across Global instances or called from multiple threads at once.

This stack pool is per-`LuaClosure`, so this should be safe under LuaJ's guarantees - `LuaClosure`s shouldn't be shared across `Global` instances or called from multiple threads at once.

Pull request closed

Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-autonomous-connection/luaj#76