MicroPython Startup Time

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
kevinkk525
Posts: 601
Joined: Sat Feb 03, 2018 7:02 pm

Re: MicroPython Startup Time

Post by kevinkk525 » Fri Jan 24, 2020 7:27 am

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

User avatar
pythoncoder
Posts: 3925
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: MicroPython Startup Time

Post by pythoncoder » Sat Jan 25, 2020 9:52 am

@Mike Teachman Would it help to have a separate main.py and app.py (maybe both frozen) with main.py being (pseudocode):

Code: Select all

feed watchdog
import app
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.
Peter Hinch

User avatar
Mike Teachman
Posts: 80
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: MicroPython Startup Time

Post by Mike Teachman » Sat Jan 25, 2020 10:11 pm

pythoncoder wrote:
Sat Jan 25, 2020 9:52 am
Would it help to have a separate main.py and app.py (maybe both frozen) with main.py being (pseudocode):
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!

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)
Pyboards

Code: Select all

from machine import Pin
start = Pin('X6', Pin.OUT)
start.value(1)
Startup results for Micropython, best to worst (startup = rising edge of RST to rising edge of GPIO pin)
  • 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
Arduino tests
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() {
}
Startup results for Arduino (startup = rising edge of RST to rising edge of GPIO pin)
  • Lolin D32 (ESP32 w/ no psram): 170ms (vs 588ms in MicroPython)
  • Lolin D32 Pro (ESP32 w 4MB psram): 200ms (vs 1.75s in MicroPython)
It's interesting to see that Pyboard startup times in MicroPython are about 3x faster than ESP32 startup times with compiled C

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
Roberthh wrote:
Wed Dec 11, 2019 7:07 pm
Time from trailing edge of the reset signal to that pulse ~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.
DS1Z_QuickPrint5.png
DS1Z_QuickPrint5.png (40.88 KiB) Viewed 157 times

User avatar
tve
Posts: 59
Joined: Wed Jan 01, 2020 10:12 pm
Location: Santa Barbara, CA
Contact:

Re: MicroPython Startup Time

Post by tve » Sun Jan 26, 2020 6:23 am

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.

User avatar
Roberthh
Posts: 1838
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython Startup Time

Post by Roberthh » Sun Jan 26, 2020 7:46 am

@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.
boot_time.jpg
boot_time.jpg (59.65 KiB) Viewed 109 times

User avatar
Mike Teachman
Posts: 80
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: MicroPython Startup Time

Post by Mike Teachman » Fri Jan 31, 2020 3:33 am

Roberthh wrote:
Sun Jan 26, 2020 7:46 am
You might improve @pythoncoder's suggestion by putting the first dog feeding into boot.py.
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
DS1Z_QuickPrint1.png
DS1Z_QuickPrint1.png (42.36 KiB) Viewed 83 times

User avatar
Roberthh
Posts: 1838
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: MicroPython Startup Time

Post by Roberthh » Fri Jan 31, 2020 8:12 am

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

Post Reply