I remember someone saying that 'is on-screen' is a good way to get better performance since it lets the engine only run calculations on objects that are on screen
But with this set of events at about 50 objects 'is on-screen' tanks performance. It runs MUCH better with the condition simply disabled
Develop games in your browser. Powerful, performant & highly capable.
This doesn't make sense. "Is on screen" works fast, I tested it with 10000 objects and it didn't make any noticeable difference in performance. Definitely shouldn't matter for 50 objects.
In your case you don't really need this check, because you are only changing a bunch of variables. It's useful when you have CPU-intensive behaviors applied on objects, like Platform or Physics. Then you can disable these behaviors when objects are off-screen and improve performance.
I don't know why your code runs faster with this condition disabled. I'm guessing that off-screen object instances have empty values in these variables (direction, animation, lastX, lastY) and some other events don't work effectively with them.