How can I make my video plugin faster?
#1
I have a video plugin, it's based on the Video Example plugin in the wiki.

When looking at the log, everytime I load a list it takes about 4 seconds, but 3 of those 4 seconds is the actual plugin loading. 

Various lines in the log of CPythonInvoker. 

The work of getting the list from server and formatting to list items only takes about 0.5 seconds.

Is there anyway to make it faster? Possibly keeping the plugin running or something so that the loading part doesn't have to be duplicated every time?
Reply
#2
you could try if adding reuselanguageinvoker to your addon.xml file makes a difference.
example: https://github.com/xbmc/xbmc/blob/7d6ecc...on.xml#L13
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
(2021-09-27, 12:35)ronie Wrote: you could try if adding reuselanguageinvoker to your addon.xml file makes a difference.
example: https://github.com/xbmc/xbmc/blob/7d6ecc...on.xml#L13

Thank you for the suggestion, it didn't seem to make a difference though. 

Is it possible to keep a plugin running like as a service and still access it via the plugin:// urls for getting directory lists?
Reply
#4
In addition to trying reuselanguageinvoker it is strongly recommended to move all your "business" logic into imported modules leaving the entrypoint script as small as possible. The Python interpreter has to re-compile the entrypoint script into bytecode on each run but bytecode for imported modules is cached (as .pyc files).
Reply
#5
(2021-09-27, 18:52)hattmall Wrote: Is it possible to keep a plugin running like as a service

nope, a plugin needs to exit as soon as possible.

a loading time of 3-4 secs. seems awfully long to me...
perhaps you could post a link to your addon code, so one of us could check if there's something obvious going wrong.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#6
So I determined that this issue is caused by importing the "requests" module. I saw a few threads about it being slow but didn't see a clear resolution. 

Is there any alternative that can be used instead of requests? I only do a few very simple get and post requests.
Reply
#7
(2021-09-28, 04:38)hattmall Wrote: So I determined that this issue is caused by importing the "requests" module. I saw a few threads about it being slow but didn't see a clear resolution. 

Is there any alternative that can be used instead of requests? I only do a few very simple get and post requests.

To add, as a fix I removed the importation of requests, and just used urllib and wrote a small function. 

python:
def get_data(theurl):

    resp = urllib.urlopen(theurl)
    html = resp.read()
    return html

I then replace every instance of request.get with get_data.

I tried both urllib and urlib2. urllib2 took 700ms to import and urllib was only 500ms.

I would still be interested in another alternative to urllib though because 500ms is still pretty long, as of right now thats about 50% of my entire load time including getting data from server and processing.
Reply
#8
(2021-09-28, 05:48)hattmall Wrote:
(2021-09-28, 04:38)hattmall Wrote: So I determined that this issue is caused by importing the "requests" module. I saw a few threads about it being slow but didn't see a clear resolution. 

Is there any alternative that can be used instead of requests? I only do a few very simple get and post requests.

To add, as a fix I removed the importation of requests, and just used urllib and wrote a small function. 

python:
def get_data(theurl):

    resp = urllib.urlopen(theurl)
    html = resp.read()
    return html

I then replace every instance of request.get with get_data.

I tried both urllib and urlib2. urllib2 took 700ms to import and urllib was only 500ms.

I would still be interested in another alternative to urllib though because 500ms is still pretty long, as of right now thats about 50% of my entire load time including getting data from server and processing.

Really hope you're using some method of url caching Big Grin
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#9
(2021-09-28, 06:26)Lunatixz Wrote:
(2021-09-28, 05:48)hattmall Wrote:
(2021-09-28, 04:38)hattmall Wrote: So I determined that this issue is caused by importing the "requests" module. I saw a few threads about it being slow but didn't see a clear resolution. 

Is there any alternative that can be used instead of requests? I only do a few very simple get and post requests.

To add, as a fix I removed the importation of requests, and just used urllib and wrote a small function. 

python:
def get_data(theurl):

    resp = urllib.urlopen(theurl)
    html = resp.read()
    return html

I then replace every instance of request.get with get_data.

I tried both urllib and urlib2. urllib2 took 700ms to import and urllib was only 500ms.

I would still be interested in another alternative to urllib though because 500ms is still pretty long, as of right now thats about 50% of my entire load time including getting data from server and processing.

Really hope you're using some method of url caching Big Grin

When you say URL caching do you mean like the Kodi plugin url, like plugin:// or the actual url of the server, like the http://, or both!?
Reply
#10
(2021-09-29, 03:10)hattmall Wrote:
(2021-09-28, 06:26)Lunatixz Wrote:
(2021-09-28, 05:48)hattmall Wrote: To add, as a fix I removed the importation of requests, and just used urllib and wrote a small function. 

python:
def get_data(theurl):

    resp = urllib.urlopen(theurl)
    html = resp.read()
    return html

I then replace every instance of request.get with get_data.

I tried both urllib and urlib2. urllib2 took 700ms to import and urllib was only 500ms.

I would still be interested in another alternative to urllib though because 500ms is still pretty long, as of right now thats about 50% of my entire load time including getting data from server and processing.

Really hope you're using some method of url caching Big Grin

When you say URL caching do you mean like the Kodi plugin url, like plugin:// or the actual url of the server, like the http://, or both!?

Assuming your code is optimal and not at fault for the performance issues.

1. If your plugin scrapes a website/api/etc. It's strongly recommended you cache the URL response which will reduce the burden on the site and dramatically speed up plugin navigation. I recommend simplecache (https://github.com/kodi-community-addons...implecache).

2. Enabling "cachetodisc" can help: https://codedocs.xyz/xbmc/xbmc/group__py...0d8d77fff6

3. Don't forget to follow @ronie suggestion which will increase performance. 
(2021-09-27, 12:35)ronie Wrote: you could try if adding reuselanguageinvoker to your addon.xml file makes a difference.
example: https://github.com/xbmc/xbmc/blob/7d6ecc...on.xml#L13
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#11
(2021-09-29, 18:06)Lunatixz Wrote:
(2021-09-29, 03:10)hattmall Wrote:
(2021-09-28, 06:26)Lunatixz Wrote: Really hope you're using some method of url caching Big Grin

When you say URL caching do you mean like the Kodi plugin url, like plugin:// or the actual url of the server, like the http://, or both!?

Assuming your code is optimal and not at fault for the performance issues.

1. If your plugin scrapes a website/api/etc. It's strongly recommended you cache the URL response which will reduce the burden on the site and dramatically speed up plugin navigation. I recommend simplecache (https://github.com/kodi-community-addons...implecache).

2. Enabling "cachetodisc" can help: https://codedocs.xyz/xbmc/xbmc/group__py...0d8d77fff6

3. Don't forget to follow @ronie suggestion which will increase performance. 
(2021-09-27, 12:35)ronie Wrote: you could try if adding reuselanguageinvoker to your addon.xml file makes a difference.
example: https://github.com/xbmc/xbmc/blob/7d6ecc...on.xml#L13

Am I reading this right that cacheToDisc is enabled by default ?


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#12
(2021-09-29, 18:59)jbinkley60 Wrote:
(2021-09-29, 18:06)Lunatixz Wrote:
(2021-09-29, 03:10)hattmall Wrote: When you say URL caching do you mean like the Kodi plugin url, like plugin:// or the actual url of the server, like the http://, or both!?

Assuming your code is optimal and not at fault for the performance issues.

1. If your plugin scrapes a website/api/etc. It's strongly recommended you cache the URL response which will reduce the burden on the site and dramatically speed up plugin navigation. I recommend simplecache (https://github.com/kodi-community-addons...implecache).

2. Enabling "cachetodisc" can help: https://codedocs.xyz/xbmc/xbmc/group__py...0d8d77fff6

3. Don't forget to follow @ronie suggestion which will increase performance. 
(2021-09-27, 12:35)ronie Wrote: you could try if adding reuselanguageinvoker to your addon.xml file makes a difference.
example: https://github.com/xbmc/xbmc/blob/7d6ecc...on.xml#L13

Am I reading this right that cacheToDisc is enabled by default ?


Jeff

Correct...
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply

Logout Mark Read Team Forum Stats Members Help
How can I make my video plugin faster?0