Discuss Scratch
- Discussion Forums
- » Questions about Scratch
- » How to optimize!!!!!
- lucasbroo
-
27 posts
How to optimize!!!!!
I am making a huge project, but it needs to be heavely optimized. What makes projects the most laggy? is there a list? help plz!!!!!!
- meunspeakable
-
100+ posts
How to optimize!!!!!
For macro optimizations, there aren't strict/straightforward principles, but there is this project for micro optimizations: https://scratch-mit-edu.ezproxyberklee.flo.org/projects/1030987979/
Edit: Forgot about time complexity for macro optimizations. see post below.
Edit: Forgot about time complexity for macro optimizations. see post below.
Last edited by meunspeakable (Jan. 19, 2025 20:43:03)
- TheCreatorOfUnTV
-
1000+ posts
How to optimize!!!!!
This project will probably help you with larger optimizations.
However, for smaller optimizations, I'd instead recommend this project.
However, for smaller optimizations, I'd instead recommend this project.
Last edited by TheCreatorOfUnTV (Jan. 19, 2025 20:38:57)
- Voxalice
-
1000+ posts
How to optimize!!!!!
Here's a list of common optimization strategies in Scratch:
I would also recommend checking out the projects that the people above me have recommended
- Remove any unnecessary code lying around in the editor.
This includes:
- Duplicate code; code that doesn't need to be repeated in multiple places
- Unreachable code; code that will never be run, including detached scripts
- Dead code; code that runs, but does nothing - Experiment with the “run without screen refresh” option.
Sometimes, a custom block that runs without screen refresh is great, since it runs a lot faster than with screen refresh.
However, if a custom block that runs without screen refresh takes too long to run, it may freeze the project.
Try checking and un-checking the “run without screen refresh” option on custom blocks you use. - Use less clones.
Clones lag a lot because they're basically just full-fledged sprites.
Imagine creating 300 sprites that all run code at the same time; that's basically what happens when you make 300 clones.
If you use a lot of clones, try reducing the amount of clones you use and see if the lag goes away. - Create a blank sprite, then move it to the left of every other sprite.
This makes projects less laggy when they're played outside of the editor. - Convert images from vector to bitmap.
Scratch uses a lot more memory to store vector images than bitmap images. - Avoid Firefox.
Firefox runs projects slower than Chromium-based browsers, like Google Chrome.
Try using another browser to run your project and see if the lag goes away. - Just experiment.
Sometimes, Scratch will run some code slower than other code for no obvious reason.
Try rearranging scripts and experimenting with the structure of your code to see if it runs faster. - Try using @Vadik1's project.json minimizer.
This probably won't help with lag, but it will make your project smaller in file size. - If all else fails, redirect your project's viewers to TurboWarp.
TurboWarp compiles Scratch projects, making them run much faster than normal.
This does mean you have to send your viewers outside of Scratch, which is why I consider it a last resort.
I would also recommend checking out the projects that the people above me have recommended

Last edited by Voxalice (Jan. 19, 2025 20:44:39)
- XCardx
-
28 posts
How to optimize!!!!!
I’ve found that reducing the amount of code blocks being ran each frame to be the most generally effective way to optimize code. However avoiding the use of certain blocks, such as the one that checks if a list contains something, can be more effective, however the performance impact of those blocks tends to be highly circumstantial and extremely inconsistent. Also scratch loads the code blocks sort of as entities for the first sprite by default, and for some reason that effects performance in both the editor and the project page, so make sure the first sprite is completely empty, and while testing the code while in the editor select that sprite to see how the project does for viewers. Also the script stop block is incredibly laggy, I don’t know why, but it can often create vastly more lag than it’s capable of getting rid off, but in some situations it can be used to overall improve performance by stopping large amounts of unnecessary code from running, for example stopping a custom block from running continuing to do a complex task once said task is done. And sometimes with scratch a change to the code can speed up or slow down a script for no apparent reason whatsoever, so keeping trying different ways to code your scripts until you get something your happy with.
- Discussion Forums
- » Questions about Scratch
-
» How to optimize!!!!!