Maximising Performance

Maximising the performance of the VBOX Touch can be very important, particularly when writing larger programs or ones with high amounts of data processing. Here are a few ways you can do so.

Collecting Garbage

Garbage collection is one of the most common things that slows your VBOX Touch or rather causes random spots of lags/random stops in your program.

You can however call this yourself at better times to help reduce it being called at times that are bad for you. This is done using gc.collect(). For more about this and other garbage collection functionality see Garbage Collection

Floating point calculations

Performing floating point calculations takes a lot of time when compared to integer calculations. Because of this, it is advised to perform calculations in integers wherever possible and only convert to floats after or when a higher degree of precision is needed.

Using ustruct

Packing values into binary form with ustruct is faster and uses less memory than manipulating them as strings or lists; use it when handling binary protocols such as CAN or serial data.

Using redraw

When you are creating a GUI you will have to show it at some point using gui.show(). However, when updating this display you do not need to use the gui.show() function again.

Instead, you can use the gui.redraw() function which will update any data that has changed (so long as this data is mutable). This saves a lot of processing as the VBOX Touch does not need to generate the entire page again.

To ensure that you get all updates to your information it is advised that you put the gui.redraw() function in vsync_cb as this callback happens very frequently.

Allocating memory

Pre-allocate buffers (for example with bytearray) once and reuse them, rather than creating new objects inside loops, to reduce garbage-collection pauses.

Further Reading

For more ways you can maximise the performance of your micropython code, see the MicroPython Docs on speed.