monome / norns

norns is many sound instruments.
http://monome.org
GNU General Public License v3.0
630 stars 145 forks source link

lua VM reset questions #449

Closed catfact closed 6 years ago

catfact commented 6 years ago

i'm making this issue to document some reservations i have about resetting the lua VM as a normal part of norns operation (e.g. every time a script is launched) - specifically in regards to the C layer. (i have other reservations about the lua layer and usability, but they are more vague at this point.)

since the state must be torn down outside of a lua call, it is structured as an event. when lua requests a LVM reset, weaver posts a reset event, and the destruction and re-instantiation of the LVM happens in the event loop. this is important to keep in mind.

when norns first booted, the LVM is created and the startup script run before the event loop starts ticking. startup script can take as much time as it needs, and everything is fine.

but doing it from the event loop means that events already in the queue will not be handled until startup is finished. if startup includes file access and other things that take indeterminate time, this could be really bad: for example, if the event queue fills up, it will currently just wrap around and start pushing new event data pointers, without freeing the old ones - a memory leak.

we should do some or all of the following:

and we need to run this system hard with valgrind memcheck before considering it solid.

another concern: if we do ever want to try and run event callbacks in a separate thread from the ewvent loop itself (which would be good for timing determinacy) then we would be in danger of crashes / weirdness from race conditions while the LVM is down.

catfact commented 6 years ago

closing this (we're not using lvm_reset right now) but leaving for future reference