I’m rewriting one of my frameworks and I’m trying to make a master module with one singular Heartbeat connection, and have all other scripts plug into that one singular Heartbeat. The best example is having a setup like this:
Module script with the Heartbeat connection → Module script has a table that gets functions added to it → The Heartbeat loops through the table of functions every frame and fires said functions
The only issue is that this method seems like it’d cause major memory issues down the road. The goal is to have a Heartbeat connection that I can add and remove functions to post-definition. Is the method above the only possible method?
This kinda sounds like events with extra steps. If you’re adding and removing things all the time I think it would make more sense to just use Roblox’s connection system.
I really don’t get the point of this. You’re better off connecting each individual function to Heartbeat separately, as this gives you more control, clarity, and forward compatibility (i.e. Parallel Luau). Trying to squeeze everything into a single connection comes with its own set of problems:
Error management/debug. You’ll need an intricate system of catching errors and handling them. It will also be much harder for you to debug when everything’s in a single thread/scope.
Single-threadedness. You’re putting all the processing burdens on a single thread in this day and age of multithreading. There are going to be performance implications.
Performance overhead. You will need to iterate through each function to call them every single frame.
Forward compatibility. With the release of Parallel Luau, you can expect more and more people to use it for easy performance gains, but it wouldn’t do much when everything’s forcibly stacked onto a single thread, let alone a massive one that will delay all other processes.
I’ve heard that having multiple connections to an event could cause memory issues? Like, 25+ connections. Is that just wrong or does Parallel Luau alleviate that?
EDIT: Okay yeah so I found a way to manipulate the functions in the event real-time so there’s only one connection (adding functions to a table, then having the existing function run itself and the new function relative to its existence in the table so it can be removed from the grand function. Code attached below) and from what I got out of the microprofiler, it seems like it caused more hiccups in the Heartbeat than having multiple separate connections. Problem solved