Frozen Bytecode: Maximizing RAM by Executing from Flash
To achieve minimal RAM usage, MicroPython employs 'frozen bytecode,' which allows pre-compiled Python scripts to be stored and executed directly from flash memory, rather than consuming valuable RAM during runtime.
The top 3
- RAM Savings: How Frozen Bytecode Optimizes Memory: Frozen bytecode significantly reduces RAM usage on microcontrollers by executing pre-compiled Python code directly from flash memory, preventing the need to load and parse source code into the heap.
- Top Methods for Freezing Python Bytecode: Developers primarily use `mpy-cross` to pre-compile Python scripts into `.mpy` bytecode files, which are then integrated into the MicroPython or CircuitPython firmware image during the build process, often managed via manifest files.
- Beyond RAM: Other Frozen Bytecode Advantages: In addition to saving RAM, frozen bytecode significantly boosts program startup times by eliminating on-the-fly compilation, and offers a degree of code protection by embedding modules directly into the firmware image.
Sources
Open the full topic