Replaced debug output of json.dumps with an indirection to lazy __str__.

json.dumps is a processing intensive operation. This is being called
every time data is received from the server (most noticeably during
library updates) for debug logging. If the user has debug logging
disabled (the default option) then the user is still paying for
processing which is discarded.

The fix is to add a level of indirection where the dumps function is
only called if a string representation of the json is requested; ie.
when the debug string is evaluated.
This commit is contained in:
Chuddah 2020-02-16 22:17:05 +00:00
parent 94456ddcd8
commit 7491000a13
5 changed files with 24 additions and 8 deletions

View file

@ -15,7 +15,7 @@ import downloader
import player
from client import get_device_id
from objects import PlaylistWorker, on_play, on_update, special_listener
from helper import translate, settings, window, dialog, api, JSONRPC
from helper import translate, settings, window, dialog, api, JSONRPC, debug
from jellyfin import Jellyfin
from webservice import WebService
@ -96,7 +96,7 @@ class Monitor(xbmc.Monitor):
data = json.loads(data)
LOG.debug("[ %s: %s ] %s", sender, method, json.dumps(data, indent=4))
LOG.debug("[ %s: %s ] %s", sender, method, debug.JsonDebugPrinter(data))
if self.sleep:
LOG.info("System.OnSleep detected, ignore monitor request.")