respeaker / respeaker_python_library

To build voice enabled objects/applications with Python and ReSpeaker
Apache License 2.0
149 stars 76 forks source link

slow speed for import library #2

Open juncaofish opened 7 years ago

juncaofish commented 7 years ago

Test Code with built firmware on LinkIt

import time
t = time.time()
import json
j = time.time()
print "import json cost:", j-t
import requests
r = time.time()
print "import requests cost:", r-j
import base64
b = time.time()
print "import base64 cost:", b-r

Result: import json cost: 0.510145187378 import requests cost: 14.6618149281 import base64 cost: 0.00102591514587

Any idea?

xiongyihui commented 7 years ago

Importing module is quite slow on MT7688 indeed. There are several reasons:

  1. SPI Flash R/W is very low.
  2. Many modules are not pre-compiled to byte-code due to space limitation.
  3. MT7688 is slow.

Using a SD card as extroot may improve the performance as SDIO is faster than SPI. With a SD card, more space will be available. Compiling python modules to byte-code will also increase loading speed. To do so:

python -m compileall