Strange performance issue with "Tell <sprite> to ()"

I'm not sure where this topic should go. It's definitely not a bug report nor a development ...
I try to call a sprite-local method with "Tell...".

Auto bounce script pic (2)
The above script is 5-6 times slower than the exact equivalent below
Auto bounce script pic (3)

The result defies common sense. Switching the context twice for "ask" and "tell" is faster than single "tell" with many blocks. Are there any optimizations for simple rings?

BTW: a call to the fastest sprite-local method is 10 times slower than the same method declared as global.

Example project:

I think I can solve one issue

Your global if on edge wrap block doesn't have the overhead of getting passed an object and doesn't do any ask/tell inside it

I modified it to be the same as and it runs ~~ to the sprite local version

[edit corrected my script to make it identical to the sprite local one)]

It's a long term concern about effective control structures.

I'm trying to achieve a kind of modularity and ordering using sprite-local methods. Some additional futures can be cleanly merged into a project just by importing sprite. Kind of user-level libraries without cluttering the global namespace, with additional benefits of maintaining and visualizing the state. Did You notice that edge mode behavior is based on the costume of EdgeMode sprite? It's kind of a joke but maybe can be worth noting as a DIY solution to global switches.

Backing to track - the 60 times performance penalty, for no apparent reason, for exactly the same amount of work needs some clarification.
Auto bounce script pic (5) Auto bounce script pic (4)

@bh where is the proper place for such topics? I have some additional concerns about visibility issues with local methods and the detrimental effect of syncing with animation frames.

Interesting observations, thank you. So it's more preferable to use global cutsom blocks and try not to TELL a lot.

As I pointed out - the global if on edge,warp block doesn't have a parameter and doesn't use ask/tell - if you change it to my version - the performance difference is ONLY about 10 times :slight_smile:

Yes, but it's not the point to slow down the fastest route, isn't it? And if the actual processing is done quite fast, 50-100 ms for 1000 iteration, passing parameters and "tell" can have reasonable overhead 60-100% not a few times.
Consider the worst case: single iteration took ~3 ms. The same work is done in 0.05ms by the local method.
Maybe I do something utterly wrong ...

Of course not :slight_smile:

But I think the point you are trying to make is that telling a lot of blocks to do something is much slower than 1 ask and 1 tell.

The speed difference between those two comparisons ~= 10 times - not 60 times :slight_smile:

There seems to be a small difference (about 10%) between sprite local and global running times but that is not the big issue here

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.