Without using any ram for the bytecode. The act of doing an import also executes the bytecode which may allocate RAM. I haven't played with the esp8266, so I'm not familiar enough to know whether there would be any speed penalty or how much it would be. On the pyboard there should be no penalty.Lornioiz wrote:Thank you very much Dave,[So regular bytecode takes up RAM where frozen bytecode doesn't.
That means that in a esp8266 I can import as much modules as I want (by the import statement) without using any ram if they are saved in the firmware? just curious, how severe is the speed penalty in doing so (I'm thinking about freezing as much of the application I can by splitting it in various modules)?
Support loading of .mpy files
Re: Support loading of .mpy files
Re: Support loading of .mpy files
Thanks to the developers for the ongoing development work...
It would be #hugely# helpful if someone could just post some simple instructions:
-- How to compile to mpy files
-- Where to put the mpy files so that they get frozen into the firmware build...
I note that in the discussion on the original PR, Hosaka said "The mpy-cross commit is long awaited and it would be great to see this finally added! Some docs to go along with it for the esp8266 might be due as well."
( https://github.com/micropython/micropython/pull/2502 )
Did I miss something - are there already such docs for this hugely significant addition?
Although I suspect that I can figure this out , I really feel that uPython on the ESP8266 is not getting as enthusiastic an uptake as it should simply because it takes so much research time to find out things that to the developers / more advanced users are "obvious"..
Thanks in advance.
It would be #hugely# helpful if someone could just post some simple instructions:
-- How to compile to mpy files
-- Where to put the mpy files so that they get frozen into the firmware build...
I note that in the discussion on the original PR, Hosaka said "The mpy-cross commit is long awaited and it would be great to see this finally added! Some docs to go along with it for the esp8266 might be due as well."
( https://github.com/micropython/micropython/pull/2502 )
Did I miss something - are there already such docs for this hugely significant addition?
Although I suspect that I can figure this out , I really feel that uPython on the ESP8266 is not getting as enthusiastic an uptake as it should simply because it takes so much research time to find out things that to the developers / more advanced users are "obvious"..
Thanks in advance.
Re: Support loading of .mpy files
If you build the image, you can simply put your python sources in the modules subdirectory for that build, e.g. esp8266/modules or stmhal/modules. The compilation is then called by the Makefile. The compiler is mpy-cross in mircopython/mpy-cross. YOu have to make it before you create an image for the target platform.
mpy-cross can be used independently fro the make. You need that to create .mpy files for WiPy, where these are not integrated in the flash image. On WiPy, using .mpy file sis still an advantage, because you can use code that is too large for being compiled within Wipy itself.
You can also simply copy an .mpy file into the file systems of esp8266 or PyBoard, from where they can be imported for execution.
The difference: If you put the frozen bytecode into flash, they will consume way less RAM, because the code stays in flash. If you execute them from the file system, the code will be in RAM. On esp8266, code in flash runs a little bit slower.
mpy-cross can be used independently fro the make. You need that to create .mpy files for WiPy, where these are not integrated in the flash image. On WiPy, using .mpy file sis still an advantage, because you can use code that is too large for being compiled within Wipy itself.
You can also simply copy an .mpy file into the file systems of esp8266 or PyBoard, from where they can be imported for execution.
The difference: If you put the frozen bytecode into flash, they will consume way less RAM, because the code stays in flash. If you execute them from the file system, the code will be in RAM. On esp8266, code in flash runs a little bit slower.
Re: Support loading of .mpy files
I do beg your pardon, I now realise that I was not so clear. I thought that since the announcement of the mpy files possibility, I had to do something different from before...Roberthh wrote:If you build the image, you can simply put your python sources in the modules subdirectory for that build,
I now see that nothing is different - what you explain is what I have been doing before - putting code into the 'modules' sub directory. It's just that now they are automatically pre-compiled when you MAKE.
Thanks - good stuff!