Hi,
I'm trying to get confirmation on something.
The Docs say that at start-up your python source code on the Flash memory gets compiled to byte code, this byte code gets stored in the RAM and then then the Virtual Machine interprets your byte code (which means executes your code).
Now my question: when you have a program that goes repeatedly to (deep)sleep, does your code get recompiled everytime you wake up?
I would think yes, because the byte code is stored on the RAM memory and this won't be kept in deepsleep. But I'm not certain about this.
Thanks in advance!
Does your code have to recompile everytime you wake up from (deep)sleep
Re: Does your code have to recompile everytime you wake up from (deep)sleep
Yes, if RAM is lost, then it must re-compile the code.
If this is a concern, then you can either compile your .py files to .mpy (in which case the bytecode will just be copied directly into RAM from flash), or even better, freeze the code into your firmware (in which the bytecode will be executed directly from ROM).
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Does your code have to recompile everytime you wake up from (deep)sleep
Precompiling saves time and electrical energy on wakeup because the compiler uses both.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.