-
Is dispatchEvent slower than code in class?
Hi guys,
Does dispatchEvent use any extra memory/cpu/anything compared to calling a normal function?
I plan to call it every couple of milliseconds for a timer.
Many thanks!
-
Total Universe Mod
Yes there is slightly more overhead than using a callback. dispatchEvent requires you to instantiate an event object (which is the most expensive part) and then loop over listener lists to find an object registered for that event. A callback simply triggers a function already resident in memory.
Events are still great for decoupling your code but callbacks are a nice way to optimize. Keep in mind that unless you're app is a game or game like, you may not notice a difference.
-
You may also be able to keep a pool of Event objects in the dispatching instance to re-use rather than create new ones for every dispatch.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|