This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-10-19 16:50:14

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Variables make your project slower!

For some reason, when I try to use variables to save computation and to store intermediate results (which is a practice that should be taught instead computing same thing over and over), the project gets in fact slower!

This code:

<if><( ... a long computation ... <>> <{ max }> )>
<set{ max }to( ... a same long computation ...
<end>

is in fact faster then this:

<set{ result }to( ... a long computation ...
<if><( [ result ]  <>> <{ max }> )>
<set{ max }to( [ result ]
<end>

This project http://scratch.mit.edu/projects/deerelResearch/292492
and this ecen more http://scratch.mit.edu/projects/deerelResearch/292475
measures and show it. There seems to be problem with <set{  }to( being slow for some reason, much more slower than a lengthy computation and longer than variable access (since there are variable accesses in the lengthy computation).

Offline

 

#2 2008-10-19 21:18:37

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Variables make your project slower!

Not as slow as Lists make them, I bet!


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#3 2008-10-19 21:20:31

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Variables make your project slower!

yes, the speed dropped dramatically with 1.3. I hope the Scratch team gets time to fix it up: I'm really wishing it was faster.

Offline

 

#4 2008-10-21 05:48:24

Digimath
Scratcher
Registered: 2007-07-07
Posts: 100+

Re: Variables make your project slower!

The scratch team has told us that, by design, Scratch is not performent. However, Jens once posted a note saying that he had seen some optimizing routines in the Squeak code for Scratch. Assuming that the Squeak code for Scratch and the Java code for Scatch are about the same, the combination of "designed to run slowly" and "some things are optimized" could be the cause of your unexpected performance issues.


I tried a few experiments with your project.

Code:

Results For  Complex   Variables

        Java  5.2       4.2
        IDE   5.6       5.2
        IDE   5.8       5.6  (Presentation mode)
   Turbo IDE  6.9       6.6
   Turbo IDE  7.4       7.4  (Presentation mode)

(Ran on a PC with a PD 925/3 Ghz processor using windows XP)

It looks like the cost of using a variable can be minimized in the IDE version Scratch.  Of course, since most projects are run online, its the Java performance we care about the most.


I've updated my text adventure game.
Colossal Cave 150http://scratch.mit.edu/static/projects/Digimath/3003787_sm.png

Offline

 

#5 2008-10-21 09:56:30

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Re: Variables make your project slower!

Digimath wrote:

The scratch team has told us that, by design, Scratch is not performent.

WHAT??? If this is true, than it is plain silly! I am not against steps and minimal time per step. But making a thing slow by design, thus preventing anything of decent size (tha means foir example games with lots of sprites) is everything but encouraging for programming experience. When someone tries to do something bigger than "silly school animations" he only comes to the conclusion that this programming thing is * and computers can't do anything right. This is what they want by design?

I'm shocked. Really. What they were on when doing this decision?

I'm really shocked. That's why I seem so angry at them. If this is true, I am really angry at them.

Hm.

Last edited by deerel (2008-10-21 09:58:05)

Offline

 

#6 2008-10-21 12:45:12

Digimath
Scratcher
Registered: 2007-07-07
Posts: 100+

Re: Variables make your project slower!

Here is the post that talks about the performance of Scratch: http://scratch.mit.edu/forums/viewtopic … 027#p46206.  It made sense to me but I'm not an educator.  From what I've read, the educators have made good teaching opportunities using Scratch.

However, I think the relative difference in the speed of the blocks between the Java version and the IDE version is a real problem because this creates different race conditions in some Scratch projects and has been the reason that some of them do not work when uploaded.  I would not expect the relative speeds to ever be exactly the same, but it would solve some problems if they were as close as possible.


I've updated my text adventure game.
Colossal Cave 150http://scratch.mit.edu/static/projects/Digimath/3003787_sm.png

Offline

 

#7 2008-10-21 15:06:58

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Re: Variables make your project slower!

Digimath wrote:

Here is the post that talks about the performance of Scratch: http://scratch.mit.edu/forums/viewtopic … 027#p46206.  It made sense to me but I'm not an educator.  From what I've read, the educators have made good teaching opportunities using Scratch.

Yes, this make sense for me perfectly and this is what I said about steps and minimal time per step. I understand this design, how it is great for teaching programming etc. I was not complaining against this at all. So if this is the only part of "slow by design", I take my anger back. What I was complaining about. is:

Digimath wrote:

However, I think the relative difference in the speed of the blocks between the Java version and the IDE version is a real problem because this creates different race conditions in some Scratch projects and has been the reason that some of them do not work when uploaded.  I would not expect the relative speeds to ever be exactly the same, but it would solve some problems if they were as close as possible.

That is, what I really complain about is the speed of the blocks itself, within a step. If THIS is by design, than I stay angry. And, honestly, it is SO slow, that I cannot imagine how it can be made so slow without explicitly working on it being slow. I don't know for sure because I don't have the sources of Java player. Anyway, being able to only interpret roughly 4000 primitive operations (adding, subtracting, multiplying, comparing, setting a variable) per second is a totally disastrous result.

(The number was calculated from your results and the code of the benchmark; I presume the results were from the first link)
Now i've come to the idea... I must check something (make another benchmark)...

Last edited by deerel (2008-10-21 15:16:59)

Offline

 

Board footer