compile vs freeze module (with esp32 spiram support enabled)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
aleskeyfedorovich
Posts: 28
Joined: Mon Aug 27, 2018 4:43 pm

compile vs freeze module (with esp32 spiram support enabled)

Post by aleskeyfedorovich » Thu Nov 04, 2021 2:44 pm

I've always used the already compiled micropython firmware for esp32 with spiram support.

I investigated the possibility of improving the performance of the microcontroller (ESP32 WROVER) by compiling modules with mpy-cross and/or including (?freezing?) them into the whole micropython firmware.

1. what's the difference in terms of performance between importing a complied module or including it in the firmware?

2. Is the module code visible in any of the two cases?

3. while compiling a module is relatively easy following this guide, I couldn't find an up-to-date, easy to follow guide for including modules inside the firmware, with SPIRAM enabled. Could someone link to such a resource and/or help me with the necessary operations to obtain a micropython firmware with SPIRAM enabled and a custom module frozen inside it?

Thank you

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: compile vs freeze module (with esp32 spiram support enabled)

Post by pythoncoder » Thu Nov 04, 2021 5:37 pm

The main purpose of freezing is to conserve RAM; with SPIRAM this is rarely an issue. If you cross-compile the code, the source is no longer "visible": the file contains only bytecode.
Peter Hinch
Index to my micropython libraries.

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: compile vs freeze module (with esp32 spiram support enabled)

Post by rcolistete » Thu Nov 04, 2021 10:58 pm

The import time of frozen modules is usually smaller.

For example, see some benchmarks for Pycom WiPy 3, last table of section 4.2 :
https://gitlab.com/rcolistete/micropyth ... C3%B3dulos

Yeah, I need to translate to english...
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

aleskeyfedorovich
Posts: 28
Joined: Mon Aug 27, 2018 4:43 pm

Re: compile vs freeze module (with esp32 spiram support enabled)

Post by aleskeyfedorovich » Fri Nov 05, 2021 10:21 am

thank you for your answers.

So regarding question 1. I interpret that there is no big difference in terms of performance between just compiling modules with mpy-cross and freezing them into the firmware.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: compile vs freeze module (with esp32 spiram support enabled)

Post by pythoncoder » Fri Nov 05, 2021 5:51 pm

That is correct. However performance measurements on ESP32 are not straightforward due to the chip architecture: users have reported considerable variability. Also SPIRAM adds a great deal to GC time (I've measured 100ms). SPIRAM also had a reputation for unreliability, but this may have been fixed.
Peter Hinch
Index to my micropython libraries.

bwyld
Posts: 7
Joined: Tue Oct 19, 2021 3:03 pm

Re: compile vs freeze module (with esp32 spiram support enabled)

Post by bwyld » Fri Nov 26, 2021 1:44 pm

@pythoncoder,
Do you have a pointer to somewhere recording performance measurements for micropython execution on ESP32?
I'm trying to optimise my micropython for an ESP32 (pycom) port and would be grateful for some pointers on what python constructs are more or less speedy on this arch? (and also which cause more or less heap fragmentation in exeuction)

For example,
- optimising use of dicts : is the perf better with a key which is a int, a char, a short string or a long string? what about using d.get(k) rather than d[k]? what about an array with index instead of a dict?
- try/except execution cost?
- return error result as return value or raise an exception?
- function call cost vs inlining?

I'd like my code to remain as 'nice' as possible but the performance cost can be high with python - which is not such a big deal on a server but with micropython can be a go/nogo decision...

thanks!

Post Reply