Maximize RAM: How Frozen Bytecode Saves Heap

Freezing Python bytecode allows it to execute directly from flash memory (ROM) rather than being loaded into RAM, significantly reducing heap usage and fragmentation, especially for constant objects like strings and tuples.

The top 3

  1. Frozen Bytecode's Significant RAM Savings: By executing pre-compiled bytecode directly from Flash/ROM, frozen bytecode eliminates the need to load Python source or even .mpy files into RAM for parsing and execution, leading to significant heap memory savings and reduced fragmentation.
  2. Direct Execution from Flash/ROM: Frozen bytecode is integrated into the firmware and executed directly from Flash or ROM, bypassing RAM-based parsing, compilation, and storage of bytecode, thus preserving heap memory for dynamic runtime objects.
  3. Heap Fragmentation's Foe: Frozen Bytecode's RAM Efficiency: By moving program code out of dynamic RAM into flash, frozen bytecode drastically reduces heap fragmentation, ensuring larger contiguous memory blocks are available for runtime data and object allocation, crucial for stable embedded operation.

Sources

Open the full topic