Load cached widget contents on startup to improve startup time
Opened this issue · 3 comments
On low-end systems starting extra python processes is slow. Lots of widgets which point at extra plugins all required to load the initial widgets creates processes, CPU and memory churn and results in minutes to see your first widget appear sometimes.
I recently added support for a cache feature on AutoWidget which saves a json file of a widgets contents so that on startup this is initially loaded and no additional plugins are loaded. Then a background thread will refresh each widget one by one. this reduced startup time a fair amount but a autowidget process is still loaded for each widget on startup, limiting how fast it can be. On my system this is still 1min from the kodi startup screen.
If similar caching was instead implemented in skinshortcuts the startup time would be even faster because no additional addons are loaded on startup. You would be able to browse your widgets while they are getting updated in the background. On a high-end machine the background updating would still be fast.
@anxdpanic I tried looking at the code but can't see where skinshortcuts actually loads the path for the widget to display. Is it that skinshorcuts only gets involved in specifying the path but the skin itself does the loading of the path directly?
@djay How did you solve this?
I am having the same problem on starting up kodi it takes some time to finish loading the widgets with the movies on them and the changes are minimal. I would like to be able to open Kodi and have the widgets already populated and then manually update when I want without wasting that time at the Kodi start.
I have been looking for this on the source but as you said in your last comment Skinshortcuts seems to be providing the paths but I can't find where the updating/loading is ocurring (if in the skin, or kodi, or skin shortcuts or other addon)
Hope you have already solved this and bring some insight.
Thanks
@leverageinventions I forget where but the author did answer this for me.
skinshortcuts rewrites the skin and kodi directly loads up the plugins using json-rpc for each of the paths.
There isn't a solution I've found yet without a change to kodi core. This is because the real cause of the slow down is loading many versions of the python intepreter at once for each plugin instance for each widget, and all of them doing a bunch of IO on likely a slow disk and the python global interpreter lock (GIL) could be getting involved. This is also why you will get crashing because it will often hit the memory limit.
The only thing you can to migrate this is use plugins that use caching so they at least are returning a list fastish. I put caching in autowiget for this reason. But it only helps a bit.
A better solution would be to cache the lists and have kodi use an old verison on startup and not call the plugins at all. or at least call them later after the cached list is displayed and perhaps run them in the background one at a time or a just a few concurrently.
It terms out kodi does already have a mechanism to cache lists to disk, but it isn't used in json-rpc calls widgets use and it gets wiped on startup anyway. So I made a kodi ticket about fixing caching for widgets on startup but unfortunatly I'm a python developer not a C developer so fixing this is not something I can do right now.
I did think for a bit I might have found a workaround with a plugin called listcachekeeper but thats when I found out that widgets don't actually create the listcaches in the first place. I also tried and failed to get it working on Android due to the way file permissions work
One other possible change to kodi that might help is shipping with python 3.12. In 3.12 they removed the GIL for subinterpreters (thanks to eric snow @ericsnowcurrently). This should make many plugins running at once faster but I haven't seen if this happens in reality or not yet. And its still not going to be as fast as loading it from a cache on disk. You can run kodi with 3.12 on linux but low-end systems like Android kodi ships with 3.8 I believe.