xbmc/xbmc — pull request #3674 by bavison (2013-11-18 16:10:19+00:00)
Title: Implement a window ID cache

In the course of each refresh of the visibility of controls (which is
performed every frame), there are many calls to CGUIWindowManager::GetWindow
to convert from a window's integer ID to a pointer to the corresponding
CGUIWindow pointer. This involves acquiring a lock and performing a tree walk.
Yet in practice, the same ID is looked up many times in succession, so this
benefits from a simple cache of the most recently checked ID.

I measured the effect while the Videos window of the default skin was open
(but idle) on a Raspberry Pi, and this simple change alone reduced the CPU
usage by 1.5% from 46.6% to 45.1%:

Before After
Mean StdDev Mean StdDev Confidence Change
IdleCPU% 46.6 0.9 45.1 1.2 99.8% +3.3%