Difference between revisions of "User:DavidJCobb/Stack dumping"

m
imported>DavidJCobb
imported>DavidJCobb
Line 20: Line 20:
** Minimize the amount of times you access shared resources (such as the player), in order to shorten your event handler's overall execution time.
** Minimize the amount of times you access shared resources (such as the player), in order to shorten your event handler's overall execution time.
*** Remember that your own resources can be shared. If you have a magic effect that coordinates itself via a quest, anyone with that magic effect will be sharing that quest.
*** Remember that your own resources can be shared. If you have a magic effect that coordinates itself via a quest, anyone with that magic effect will be sharing that quest.
** You can "eat" some of the stacks by having your event handlers [[RegisterForSingleUpdate - Form|RegisterForSingleUpdate(''n'')]], and doing your actual processing in an [[OnUpdate - Form|OnUpdate()]] event. If ''x'' events occur within ''n'' seconds of each other, you'll process all of those events just one time.
** If you don't need instantaneous processing and aren't using Utility.Wait(), you can "eat" some of the stacks by having your event handlers [[RegisterForSingleUpdate - Form|RegisterForSingleUpdate(''n'')]], and doing your actual processing in an [[OnUpdate - Form|OnUpdate()]] event. If ''x'' events occur within ''n'' seconds of each other, you'll process all of those events just one time.
*** Effectively, those ''x'' events will register for an update and return immediately, clearing ''x'' stacks out of memory. Then, ''n'' seconds after the ''x''th event fired, one new stack will be created to do your processing.
*** Effectively, those ''x'' events will register for an update and return immediately, clearing ''x'' stacks out of memory. Then, ''n'' seconds after the ''x''th event fired, one new stack will be created to do your processing.
** If you need to quickly process the first event in a bunch, then you can "eat" a few of the redundant stacks by using a boolean variable to prevent concurrency. Check if it's true at the start of the function, and return if it is. Otherwise, set it to true, do your processing, and then set it back to false.


=== Events that can trigger large numbers of suspended stacks ===
=== Events that can trigger large numbers of suspended stacks ===
Anonymous user