# Accelerate your Thunkable application

**URL:** https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433
**Category:** Tutorials and DIY Guides
**Tags:** community, tips, best-practice, speed
**Created:** [November 22, 2023, 6:32pm UTC](https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433 "2023-11-22T18:32:14Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![tpirowski](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tpirowski/32/165528_2.png) [@tpirowski](https://community.thunkable.com/u/tpirowski)
#### Post date: [November 22, 2023, 6:32pm UTC](https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433/1 "2023-11-22T18:32:14Z")

</div>

Since I encountered a performance problem with a complex application I programmed in Thunkable (especially on older phones), I decided to explore ways to **speed up the application** by optimizing the code for speed (sometimes at the cost of degrading its readability).

Here is the first part of my research, how to speed up Thunkable apps and optimize code for speed.

## PART 1.

I use the blocks shown below for my tests. The content under test is inserted in the middle, between Timer1\_Start and Timer1\_Stop.

First I checked how much time a million iterations of the empty loop takes, to make sure there is no significant impact on the result.

 ![Thunkable SpeedTest Block](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/e/4e4a76b21cd85993a0d730062c2fe1638d4f2671.png)

It is (on my phone) 25 ms. Since I use far fewer iterations with these tests, the error is negligible.

* * *

1. APP VARIABLE vs STORED VARIABLE, 100x

 ![APP vs STORED variable](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/4/14c93b0516ae79d7e6287a581fc7c48636c4ed80.png)

App variable (2 ms) is tremendously faster than stored variable (402 ms).  
Conclusion: avoid using stored variable in deeply nested, repeatedly executed block fragments. Use app variable instead, and only store the final result (if you need it) in stored variable.

* * *

1. CHANGE VARIABLE BY +1 vs SET VARIABLE TO VARIABLE +1, 1000x

![change by 1 vs](https://us1.discourse-cdn.com/flex015/uploads/thunkable/optimized/3X/d/3/d33173b109044f8902bf795f4547e87c0d84d89a_2_690x54.png)

Surprise! CHANGE BY +1 gets 27 ms, while SET V to VARIABLE +1 is only 8 ms (!!!). That’s more than three times faster. All the places in my code where I used CHANGE BY x, I converted to old-fashioned V = V + x.

* * *

1. FUNCTION vs DIRECT BLOC, 10000x  
 ![function vs direct](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/a/1aea92cc6398fc69e4666921548140eb7fddeca3.png)  
Another surprise. With 10000 iterations only 45 ms was enough to assign empty text to a variable. However, in function it takes an eternity, more than 120000 ms (hm, two minutes…).  
Conclusion: avoid using functions in deeply nested, repeatedly executed program fragments. Use direct błocka instead. Use functions as a grouping of bigger blocks of code, not small, few block operations, that are executed often.

* * *

For balance 😄, let’s also look at examples of three solutions that provide the same processing speed:

1. REPEAT vs FOR  

2. STACKED IF/ELSE vs IF/ELSE IF  

3. Loading (as background, element background or image) PNG, WEBL, JPG (with the same resolution and color depth). It impacts apk size only.

* * *

More tricks to speed up Thunkable code and accelerate applications in the next part **(PART2)**, soon.  
Greetings for all Thunkers

---

<div class="post-metadata">

### Author: ![matt\_conroy](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/matt_conroy/32/150843_2.png) [@matt\_conroy](https://community.thunkable.com/u/matt_conroy)
#### Post date: [November 22, 2023, 7:05pm UTC](https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433/2 "2023-11-22T19:05:47Z")

</div>

Awesome detective work here. Thank you!

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [November 22, 2023, 7:08pm UTC](https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433/3 "2023-11-22T19:08:22Z")

</div>

> [@tpirowski](#):
>
> Conclusion: avoid using stored variable in deeply nested, repeatedly executed block fragments. Use app variable instead, and only store the final result (if you need it) in stored variable.

This is really important to know about Thunkable. Stored variables are so slow! Useful but only use them to _set_ values when absolutely needed; otherwise, transfer the value to an app variable throughout your code, as you suggested.

> [@tpirowski](#):
>
> Surprise! CHANGE BY +1 gets 27 ms, while SET V to VARIABLE +1 is only 8 ms (!!!). That’s more than three times faster. All the places in my code where I used CHANGE BY x, I converted to old-fashioned V = V + x.

This is fascinating! Thank you so much for sharing these details.

> [@tpirowski](#):
>
> With 10000 iterations only 45 ms was enough to assign empty text to a variable. However, in function it takes an eternity, more than 120000 ms (hm, two minutes…).

What?! Another valuable observation. **This post should be a sticky post.**

---

<div class="post-metadata">

### Author: ![matt\_conroy](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/matt_conroy/32/150843_2.png) [@matt\_conroy](https://community.thunkable.com/u/matt_conroy)
#### Post date: [November 22, 2023, 7:18pm UTC](https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433/4 "2023-11-22T19:18:56Z")

</div>



---

<div class="post-metadata">

### Author: ![tpirowski](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tpirowski/32/165528_2.png) [@tpirowski](https://community.thunkable.com/u/tpirowski)
#### Post date: [November 22, 2023, 7:25pm UTC](https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433/5 "2023-11-22T19:25:11Z")

</div>

I hope part 2 will be more interesting. Still nice improvements are possible.

---

<div class="post-metadata">

### Author: ![tpirowski](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tpirowski/32/165528_2.png) [@tpirowski](https://community.thunkable.com/u/tpirowski)
#### Post date: [November 22, 2023, 7:29pm UTC](https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433/6 "2023-11-22T19:29:01Z")

</div>

Now I’m 100% satisfied with speed. 😃

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 22, 2023, 7:50pm UTC](https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433/7 "2023-11-22T19:50:53Z")

</div>

Hey @tpirowski 👋  
Great tips! 🎉 Looking forward to part 2!

---

<div class="post-metadata">

### Author: ![maurizio.polverini89](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/maurizio.polverini89/32/145191_2.png) [@maurizio.polverini89](https://community.thunkable.com/u/maurizio.polverini89)
#### Post date: [January 19, 2024, 9:12pm UTC](https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433/8 "2024-01-19T21:12:29Z")

</div>

I was already using the fastest method withouth knowing 🕶

Just read this, look forward part 2 too!

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 1:33pm UTC](https://community.thunkable.com/t/accelerate-your-thunkable-application/2716433/9 "2024-11-08T13:33:17Z")

</div>


