2019-07-21, 10:42
(2019-07-21, 09:44)sualfred Wrote: @roidy
Thanks for the suggestion, but that won't work without storing the name as window property as cache. And this is much more expensive than just checking if the file already exists. If file is already exists it's just updating the window property.
Edit:
"Fun fact" -> A reason why the skin helper service stuff got so slow is its caching. Sometimes it's better to keep it simple.
Umm.... I'm not sure why you say the name needs to be stored as a window property or even mention cache.... Nothing need to be cached, the value of image just need to be saved in a global variable and checked like so:-
python:old_image = ""
def image_filter(prop='listitem', file=None, radius=BLUR_RADIUS):
global old_image
image = file if file is not None else xbmc.getInfoLabel('Control.GetLabel(%s)' % BLUR_CONTAINER)
try:
radius = int(radius)
except ValueError:
log('No valid radius defined for blurring')
return
if image:
if image != old_image:
log("Image has changed")
old_image = image
blurred_image, imagecolor = image_blur(image, radius)
winprop(prop + '_blurred', blurred_image)
winprop(prop + '_color', imagecolor)
else:
log("No image change detected")
I've tested this code and it works fine.... "hashlib.md5", "xbmc.getCacheThumbName" and "xbmcvfs.exists" seem to be expensive in my testing running on a Odroid N2 S922 and timing the blur function i get the following results:-
Original code:
0.025 to 0.033 seconds / ~28 milliseconds per call
My modified code:
0.00023 to 0.00037 seconds / ~300 microseconds per call
So quite a saving.