using script.module.requests: takes too long to import in runtime
#1
I'm using requests lib in my add-on, but there is a problem with import time of library.
with my laptop (core i7 8gb ram) it's taking beetween 0.85s and 1.10s to import it. (average of 1 second)
In my Raspberry Pi model B is taking 4.36 seconds!
This is the code to test it:
Code:
import timeit
start = timeit.default_timer()
import requests
print 'request lib time: %.2fs' % (timeit.default_timer() - start)

addon.xml:
Code:
<requires>
    <import addon="xbmc.python" version="2.1.0"/>
    <import addon="script.module.requests" version="2.4.3" />
</requires>

this 4+ seconds plus the time to fetch http data makes navigation uncomfortable.

could anyone explain me what I'm doing wrong? or what is happening?
Reply
#2
Debug log? I consistently get 0.06s with that test, on a slower cpu, ssd though. timeint measures wall clock time so perhaps other processes/addons are interfering?
Reply
#3
(2015-03-08, 13:46)takoi Wrote: Debug log? I consistently get 0.06s with that test, on a slower cpu, ssd though. timeint measures wall clock time so perhaps other processes/addons are interfering?

Here is kodi.log from RaspberryPi:
01:29:59 T:1588548672 NOTICE: Thread LanguageInvoker start, auto delete: false
01:29:59 T:1588548672 NOTICE: -->Python Interpreter Initialized<--
01:29:59 T:1588548672 NOTICE: OneDrive Add-on Started: ['plugin://plugin.video.onedrive/', '2', '?action=folder&content_type=video&item_id=C899E30C041941B5!22929']
01:30:00 T:1588548672 NOTICE: urlparse time: 0.15s
01:30:00 T:1588548672 NOTICE: urllib time: 0.41s
01:30:04 T:1588548672 NOTICE: request lib time: 4.09s
01:30:07 T:1588548672 NOTICE: http request time: 2.72s
01:30:08 T:1588548672 NOTICE: login time: 1.56s
01:30:12 T:1588548672 NOTICE: request time: 3.81s
01:30:13 T:1588548672 NOTICE: total time: 8.37s

BTW, I'm running this test at runtime with kodi (not from console)
Reply
#4
I just run the test from console. It is more quickly but not enough.

Code:
OpenELEC:~/.kodi/addons/script.module.requests/lib # python
Python 2.7.3 (default, Feb 27 2015, 21:09:06)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
start = timeit.default_timer()
import requests
print 'request lib time: %.2fs' % (timeit.default_timer() - start)

[b]>>> >>> >>> request lib time: 2.69s[/b]

Once the lib is loaded, it takes 0s the next time of execution because it's cached.
But, you know, kodi always run the addon in every selection, so nothing is cached.
Reply
#5
I've also noticed it is incredibly slow to import requests on a Raspberry Pi. I replicated the issue on Arch Linux on a Model B so it probably needs to be reported as a requests issue, as it's not specific to the Kodi requests package.

Code:
[root@alarm ~]# time python -c "import requests"

real  0m4.546s
user  0m2.850s
sys   0m0.090s
Leopold's Repository: Home of LibreELEC Dev Updater ...
Reply
#6
Can you run it in cProfile to see what's taking so much time?
Reply
#7
When I last checked it seemed to be mainly sre_parse.py being called by cookielib. I'll look into it more closely when I get a chance.
I used pprofile as it doesn't require any code changes.
Leopold's Repository: Home of LibreELEC Dev Updater ...
Reply

Logout Mark Read Team Forum Stats Members Help
using script.module.requests: takes too long to import in runtime0