MicroPython Startup Time
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: MicroPython Startup Time
That's quite some startup time for the esp32.. thanks for benchmarking! It's good to have those numbers.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MicroPython Startup Time
@Mike Teachman Would it help to have a separate main.py and app.py (maybe both frozen) with main.py being (pseudocode):
The point here being to feed the dog after the firmware has booted but before your app starts to load?
There is mounting evidence that psram slows things down.
Code: Select all
feed watchdog
import app
There is mounting evidence that psram slows things down.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
- Mike Teachman
- Posts: 155
- Joined: Mon Jun 13, 2016 3:19 pm
- Location: Victoria, BC, Canada
Re: MicroPython Startup Time
Yes. That approach (main.mpy + app.mpy, both frozen) shows a faster startup compared to a single frozen main.mpy -- startup time went from 660ms to 584ms (ESP32 no psram) and from 1.80s to 1.70s (ESP32 w/ 4MB psram). Definitely better for putting out that first watchdog strobe. Thanks for the suggestion!pythoncoder wrote: ↑Sat Jan 25, 2020 9:52 amWould it help to have a separate main.py and app.py (maybe both frozen) with main.py being (pseudocode):
Here are some further startup tests using the official v1.12 binaries with various dev boards. Testing was done with a minimal 3-line main.py file, stored in the filesystem (nothing pre-compiled, nothing frozen).
ESP boards
Code: Select all
from machine import Pin
start = Pin(2, Pin.OUT)
start.value(1)
Code: Select all
from machine import Pin
start = Pin('X6', Pin.OUT)
start.value(1)
- Pyboard D: 62.4ms
- Pyboard v1.1: 64ms
- Adafruit ESP8266 Huzzah: 206ms
- Lolin D32 (ESP32 w/ no psram): 588ms
- Lolin D32 Pro (ESP32 w 4MB psram): 1.75s
Then, to isolate the MicroPython contribution to the startup time I tried an equivalent test with Arduino C ...
Code: Select all
void setup() {
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
}
void loop() {
}
- Lolin D32 (ESP32 w/ no psram): 170ms (vs 588ms in MicroPython)
- Lolin D32 Pro (ESP32 w 4MB psram): 200ms (vs 1.75s in MicroPython)
note: my Pyboard startup tests showed different results than @Roberthh. Both showed a fast startup but I saw startup times in the 60ms range vs @Roberthh at ~8.4ms
I'm just getting started with Pyboards so I'm likely doing something wrong (any ideas?). Here is an oscilloscope capture for the Pyboard D startup.
Re: MicroPython Startup Time
200ms for the esp32 is about right. The boot ROM performs a consistency check on the ROM, memory, and flash storage at boot, which takes about that amount of time. It's a deliberate design choice by Espressif.
Re: MicroPython Startup Time
@mike teachman I repeated that test for Pyboard 1.1 with mostly the same results:
time reset->boot.py: 9.5 ms
time reset->main.py: 77 ms
The results for Pyboard D should be about the same. You might improve @pythoncoder's suggestion by putting the first dog feeding into boot.py.
time reset->boot.py: 9.5 ms
time reset->main.py: 77 ms
The results for Pyboard D should be about the same. You might improve @pythoncoder's suggestion by putting the first dog feeding into boot.py.
- Mike Teachman
- Posts: 155
- Joined: Mon Jun 13, 2016 3:19 pm
- Location: Victoria, BC, Canada
Re: MicroPython Startup Time
I tried this test with a non-psram ESP32 and unfortunately it doesn't make much of an impact. Only a 30ms improvement by moving the first watchdog feed to boot.py. but, it's something !
yellow=reset
green=GPIO in boot.py
purple=GPIO in main.py
Re: MicroPython Startup Time
I repeated your test with various ESP32 models, and the results are even worse.
Wemos LOLIN32 lite w/o PSRAM, code in boot.py, ESP-IDF 4: 720 ms
Wemos LOLIN32 lite w/o PSRAM, code in _boot.py, ESP-IDF 4: 690 ms
Wemos LOLIN32 pro with PSRAM, code in boot.py, ESP-IDF 4: 2160 ms
Pycom LoPy4 with PSRAM, PyCom firmware, ESP-IDF 3.1: 2200 ms
Wemos LOLIN32 lite w/o PSRAM, code in boot.py, ESP-IDF 4: 720 ms
Wemos LOLIN32 lite w/o PSRAM, code in _boot.py, ESP-IDF 4: 690 ms
Wemos LOLIN32 pro with PSRAM, code in boot.py, ESP-IDF 4: 2160 ms
Pycom LoPy4 with PSRAM, PyCom firmware, ESP-IDF 3.1: 2200 ms