jsonrpc: optimize handling of properties requested by the client #1581

Merged
merged 1 commit into from Oct 9, 2012

Projects

None yet

2 participants

@Montellese
Member

Up until now FillDetails, which contains a loop to go through all the properties requested by the client in a request has been called at least twice (once for the CFileItem and once for the CFooInfoTag) for every media item matching the client's request. With n items and m properties this resulted in n * 2 * m loops which can result in longer response times. By removing the already matched properties from the list of requested properties we get down to n * m loops. Especially for "expensive" properties like "thumbnail" and "fanart" which require additional SQL queries avoiding doing the same work twice which can have a huge impact.
In addition moving the logic to retrieve any requested properties directly from the serialization of the media item instead of first checking and handling any special cases results in additional speed-up by not having to do the extra string comparisons and map-lookups required for the special cases.

I mainly put this up as a PR (it's actually more of a fix) because I don't like all the

fields.erase(field);
continue;

and thought maybe someone has an idea for this. The only thing I could come up with was replacing those lines with a goto but I hope there's another solution.

@Montellese Montellese was assigned Oct 9, 2012
@jmarshallnz
Member

Put the inside of the loop into a separate function that returns true of false depending on whether the field should be removed or not. Early return true instead of continue to indicate you can remove it from the set. (i.e. a goto in disguise)

@Montellese
Member

@jmarshallnz Yup that's probably the cleanest approach. I've adopted it.

@Montellese Montellese jsonrpc: optimize handling of properties requested by the client
Up until now FillDetails, which contains a loop to go through all
the properties requested by the client in a request has been called
at least twice (once for the CFileItem and once for the CFooInfoTag)
for every media item matching the client's request. With n items
and m properties this resulted in n * 2 * m loops which can result
in longer response times. By removing the already matched properties
from the list of requested properties we get down to n * m loops.
Especially for "expensive" properties like "thumbnail" and "fanart"
which require additional SQL queries avoiding doing the same work
twice which can have a huge impact.
In addition moving the logic to retrieve any requested properties
directly from the serialization of the media item instead of first
checking and handling any special cases results in additional
speed-up by not having to do the extra string comparisons and map-
lookups required for the special cases.
ef7cae0
@Montellese Montellese merged commit e811d6b into xbmc:master Oct 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment