Frozen Bytecode (.mpy) in firmware vs in file system

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
fefe
Posts: 8
Joined: Tue May 28, 2019 5:52 pm

Frozen Bytecode (.mpy) in firmware vs in file system

Post by fefe » Fri May 31, 2019 4:38 pm

Hi,

I am curious to know the differences/advantages/disadvantages of Frozen Bytecode (.mpy) in firmware (as a module) vs in the file system.

Thank you in advance.

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

Re: Frozen Bytecode (.mpy) in firmware vs in file system

Post by pythoncoder » Fri May 31, 2019 5:58 pm

Putting a .mpy file in the filesystem removes the need for the device to compile the file: this can be a problem with large sourcefiles and devices with little RAM. However doing this doesn't reduce the RAM used at runtime as the bytecode has to be pulled into RAM for execution.

Compiling the code as frozen bytecode enables the bytecode to be run directly from flash (if the CPU hardware supports this). There can be a dramatic reduction in runtime RAM usage.

The symptom of the compiler running out of RAM is a memory error when you import a Python source module at the REPL.
Peter Hinch
Index to my micropython libraries.

Post Reply