FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Qt5: Eliminate slow path when showing messages by pwuertz · Pull Request #4894 · matplotlib/matplotlib · GitHub

Repository navigation

Qt5: Eliminate slow path when showing messages - #4894

Merged
mfitzp merged 1 commit into
matplotlib:masterfrom
pwuertz:qt5_slow_message_fix
Aug 10, 2015
Merged

mfitzp merged 1 commit into
matplotlib:masterfrom
pwuertz:qt5_slow_message_fix

Conversation

pwuertz commented Aug 10, 2015

Copy link
Copy Markdown
Contributor

For every single mouse-move event the Qt5 backend displays a message (x, y coordinates) via QStatusBar.showMessage(). This function forces an immediate update of the GUI and causes the application to lag behind mouse movements in case the update process cannot keep up with the event-rate.
As an alternative approach I added a QLabel to the QStatusBar and changed its text property for displaying messages. The redraws for message updates are now handled asynchronously and thus result in much better GUI performance, at least on the systems I tested.

tacaswell added this to the next point release milestone Aug 10, 2015

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Do you know what this comment is referring to?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looking at the history it seems that connecting the showMessage slot directly resulted in a segfault in PySide. The _show_message wrapper appears to be a workaround.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can we drop this helper function and just hook up self.statusbar_label.setText to the proper signal?

pwuertz mentioned this pull request Aug 10, 2015

Copy link
Copy Markdown
Member

Seems reasonable to me. Still not sure I understand the underlying cause of the regression.

attn @mfitzp

mfitzp commented Aug 10, 2015

Copy link
Copy Markdown
Member

Looks good to me. Using the QLabel in the statusbar should also work around the PySide bug that the comment # Fixes a PySide segfault. is referring to.

@tacaswell the QStatusBar.showMessage() is apparently for short temporary messages and (apparently) forces an automatic redraw of the UI as well as emitting some other Qt signals. That's a lot to be doing on every mouse movement. By switching to a QLabel the setting of the label and the UI update are decoupled and control can be handed straight back to matplotlib.

I think the regression is a combination of the increased mouse events in Qt5, possibly some slowness in matplotlib and using a slower (blocking) method to update the statusbar. Any of those individually probably wasn't an issue, but the combination leads to noticeable lag.

Relevant (unanswered) post about slowdown caused by QStatusBar.showMessage()

pwuertz commented Aug 10, 2015

Copy link
Copy Markdown
Contributor Author

The cause of the regression is the increase in mouse events from Qt5. They are emitted at rates at which you cannot synchronously update the GUI any more - which one isn't supposed to do in the first place. Again, I think this problem was present in the code all along, it's just that you won't notice it if the event rates are low enough (i.e. not like a typical regression caused by a specific code change).

In the debugger you can see that when the showMessage() call is executed, the GUI is updated immediately. The correct behaviour would be to trigger a redraw of the status bar without forcing a redraw in the event handling thread. You could argue that this is a usability/documentation bug in showMessage() since it isn't suited for rapid message updates for that reason.

Copy link
Copy Markdown
Member

@mfitzp Please do the honors of merging if/when you are happy with this?

[edit typing, reading mid-sentence, and then typing again is hard]

mfitzp commented Aug 10, 2015

Copy link
Copy Markdown
Member

Tested with PyQt4, 5 and PySide without problems.

mfitzp added a commit that referenced this pull request Aug 10, 2015
Qt5: Eliminate slow path when showing messages
mfitzp merged commit 8a2aab2 into matplotlib:master Aug 10, 2015

pwuertz commented Aug 10, 2015

Copy link
Copy Markdown
Contributor Author

It would be interesting to see how a QtQuick based approach performs, since event handling and scene drawing are decoupled more rigorous. I'd expect selectionbox/rubberband and the xy-coordinate text to perform better with this framework.

Copy link
Copy Markdown
Member

Thanks both of you.

@mfitzp I think this is your first merge to master, congratulations!

mfitzp commented Aug 10, 2015

Copy link
Copy Markdown
Member

@tacaswell It is, thanks! waits for things to explode

pwuertz deleted the qt5_slow_message_fix branch August 10, 2015 14:49
tacaswell mentioned this pull request Aug 11, 2015
14 of 17 tasks

TD22057 commented Aug 11, 2015

Copy link
Copy Markdown
Contributor

FYI Qt5 has a change (vs Qt4) in the way they report mouse events which considered a bug. The patch in the bug report does restore the Qt4 behavior which is much better. See: https://bugreports.qt.io/browse/QTBUG-40889

pwuertz commented Aug 11, 2015

Copy link
Copy Markdown
Contributor Author

Let's quickly fix all slow-paths then while they are so extremely noticeable ;)

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL