-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cron memory management with Lua table #3159
base: dev
Are you sure you want to change the base?
Conversation
89ad020
to
12e3795
Compare
// Allocate userdata | ||
|
||
// Grab the table of all entries onto the stack | ||
lua_rawgeti(L, LUA_REGISTRYINDEX, cronent_table_ref); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cronent_table_ref
contains a list of ud's and we scan for empty slots, scan for a specific one etc. I just wonder if we would we better off using a keyed table with the ud as the key, and just let the table access functions do all this for us.
The comment below isn't what the scan does, which is scan from the start of the table looking for the first null slot.
On a separate note, just in terms of efficiency scanning up a list for a null slot must terminate (possibly by throwing and EOM) so this scan could be more efficiently written:
while(lua_rawgeti(L, -1, ix) != LUA_TNIL) { lua_pop(L, 1); ix++; }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoop, yes, the comment's stale.
I thought about using the ud
as both the key and value, but this was a straightforward bring-over of existing logic, AIUI array-like tables are smaller in memory, and I think we should drop table entirely and just equip each cron entry with a timer as part of fixing #3160.
CI build failure
|
Ah, I think that's a 5.3 vs 5.1 thing. Let's hold on this PR until @TerryE's done the requisite backporting? Or I could go put the call to |
Pin a table to the registry and use that instead of manually allocating and reallocating and shuffling integers around. Thanks to @TerryE for some style suggestions.
Refactor
cron
internals to let the Lua GC do more of the work -- that is, store the list of scheduled cron elements as a Lua table. While here, permit an entry'sschedule()
function to reuse the existing schedule.dev
branch rather than formaster
.docs/*
.