[ButtonScreen] Efficiency issue in extracting help info

Issue #707 resolved
prl created an issue

When a help screen is being constructed where a helpableButtonSetupActionMap is used (currently only in InfoBarButtonSetup), InfoBarButtonSetup.getHelpText() is called for each entry in ButtonSetup.ButtonSetupKeys. Each call of getHelpText() calls ButtonSetup.getKeyFunctions(), which splits the button function assignments for the key, and calls ButtonSetup.getButtonSetupFunctions() for each function assignment and checks whether the button function assignments are in the returned list. If the button has no function assignments, the split returns an empty string, and that is also checked against the list returned by getButtonSetupFunctions(), even though the empty string cannot match. There are typically many more empty string matches than legitimate matches.

This means that extracting the help from a helpableButtonSetupActionMap() call is O(N^2). Avoiding the matches against empty strings doesn't change that, but it does reduce N by a considerable amount.

There are some further less important optimisations possible:

There are a few list comprehensions filtering the list returned by helpableButtonSetupActionMap(), and they all fully instantiate the filtered list and then only select that list. This can be improved by using next(... list filter comprehension ...) to only iterate in the generator until the first match.

There are also a number of unnecessary eval() calls in the general form: eval("config.misc.ButtonSetup." + key + ".value.split(',')") The eval() can be avoided by using getattr(): getattr(config.misc.ButtonSetup, key).value.split(',').

The overall effect of these improvements is to decrease the run time of HelpMenuList__init__() on the live TV help from about 1650 to about 700ms on a T3 (the absolute speedup will be less on faster models), and noticeably improves the time to open the live TV help screen on the T3.

Comments (2)

  1. Peter Urbanec

    Fix Issue #707: [ButtonScreen] Efficiency issue in extracting help info

    Improve average speed of InfoBarButtonSetup.getKeyFunctions() when used when extracting an ActionMap's help information by only searching the getButtonSetupFunctions() list if the strings in config.misc.ButtonSetup.<keyname> are non-empty.

    In all cases where config.misc.ButtonSetup.<keyname> is used, use getattr() to get the relevant config entry instead of using eval over a constructed string, saving the need to compile the expression.

    Where the list returned getButtonSetupFunctions() is being searched for a match, avoid constructing a list of all matches and terminate early by using next(...generator..., None) instead of generating a list from a full search.

    → <<cset d6acc19667fa>>

  2. Log in to comment