caching for viewRect of LinearRegionItem to reduce CPU load#1391
caching for viewRect of LinearRegionItem to reduce CPU load#1391j9ac9k merged 2 commits intopyqtgraph:masterfrom
Conversation
|
Thanks for this PR! As I frequently use linear region items I've been suspicious of some performance issue when using a significant number of them... I'll try and review/test this in the next day or two. |
|
This looks great! I can't think of a reason why the caching should cause any problems here. However: why not just implement this on |
|
@campagnola I looked at the code for some other items briefly, and they seemed to have their own caching, albeit implemented in some slightly different way for each. (They also didn't seem to have any performance issues.) Figured I might break something if I try to harmonize that... |
|
@jjuod I'm good w/ implementing it at |
|
Ok, moved the caching to |
|
Merged, thanks for the PR @jjuod ! |
|
Managed to fix this by adding the call to |

Issue
Having a LinearRegionItem inside a ViewBox causes large CPU loads on any mouse interaction - just moving the cursor around anywhere in the ViewBox (even outside the Item) takes up 2 threads at 100 % for me. This seems to be caused by
viewRect()of the LinearRegionItem, which is called on every mouse event and does some heavy coordinate transforms.Solution
Similar issues elsewhere in Qt/pyqtgraph seem to be solved by caching the boundaries. I suspected that the
viewTransformChanged()slot on pyqtgraph's GraphicsItem was intended specifically to allow that, so I set up a simple cache which is invalidated byviewTransformChanged(). This seems to work (CPU load reduced ~20x), but I'm not sure if that slot really catches every change that invalidatesviewRect. Would be good if someone with better understanding could take a look.