New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scatter Plot Improvements #1420
Conversation
Yields significant performance improvements when updating the scatter plot's options. See e.g. the plot hover example.
Speedups for ScatterPlotSpeedTest.py: ~50% without pxMode ~ 0% pxMode with useCache ~30% pxMode without useCache
Looks like one of the examples is hanging when running on pyside2/conda-forge instances. I recently merged #1302 which did some changes on how the test application is loaded, and how the test suite is ran in context of the examples. Can you replicate locally? |
I noticed I used a format string in the example I changed and pushed a compatibility fix while the checks were still running. Could this have something to do with it? |
Just found some more room for improvement. Should get a ~2x boost in pxMode in the next commit (~3x overall). It'll change a fair bit though, so should it be put in a separate PR? |
I ended up pushing the extra commit as it turned out to be a pretty simple change after all. |
Looks like those pipelines are hanging, I'll try to test out locally and see if I can repliace. |
I can confirm the issue locally, I get a crash when running the
passing
Running pytest without test_examples, I get a setfault on
FWIW, ignoring the examples and test_ScatterPlotItem, everything runs..
These are always tricky to debug... |
Oh joy. Installing Miniconda now. BTW, has a timeline been decided yet for when to drop support for Python2.7 and Qt4? |
I suggest looking here to see how we configure our conda environment and just replicate that: https://github.com/pyqtgraph/pyqtgraph/blob/master/azure-test-template.yml#L93-L113
I want to do it after the number of outstanding PRs gets to be 5-10ish... feel free to join our slack channel if you have some opinions on that regard. |
I just ran the scatter plot speed test at various stages throughout this PR and realized the pxMode=True gains from various commits just bring us back to roughly the original performance; serializing objects rather than using their id as the key in SymbolAtlas.getSymbolCoords was initially a big performance hit, and I was accidentally comparing to speeds after doing this. ~Doubling of the speed test for pxMode=False still appears to be correct. Apologies for overselling this. |
Thanks for following up on this. Would say this issue still resolves #1020 ? |
Also, can you explain the motivation behind serializing the objects and storing the serialized representation vs. just storing the objects themselves in the cache dictionary? |
Yes, this issue is sill resolved.
Initially I noticed that in the hovering example I added, SymbolAtlas.buildAtlas was getting called every time ScatterPlotItem.updateSpots was called, and that SymbolAtlas.symbolMap was growing without bound. The cache was missing when it shouldn't in part due to recreating new default pen and brush objects during each update. I decided to use serializations of pens and brushes in the symbolMap lookup key rather than their id to avoid this problem. I did consider instead to just avoid repeatedly recreating the default pen and brush, but realized taking this kind of care to avoid cache misses would extend to the user as well. For example, in the hover example I would have had to be careful to reuse the hovering QPen object during each update. Additionally, the SpotItem.setPen method would need to be changed to avoid creating a new QPen object. The approach I took is more forgiving to the user and avoids having to change a bunch of methods and the API. And the initially large performance hit was eventually recovered from by caching the serialized Qt objects while looping over the spots in SymbolAtlas.getSymbolCoords. For the other side of the trade-off between caching approaches: keeping all these changes but switching back to keying by id appears to boost the speed test by ~10% with pxMode=True. |
I would have never thought to serialize the objects like that! I'm not suggesting you go undo the work, but if the problem with the cache hits involve multiple calls to |
During this PR I played around with this library's Thinking more about the serialized keying: if every spot's pen or brush is different then the caching of serialized pens and brushes doesn't help alleviate the performance hit with this approach. This makes me less comfortable with the trade-off. I'm going to try out your idea now. |
I can't think of any harm of wrapping Regarding python 2.7 compatibility; ...we'll worry about that later 😆 |
Right... We need hashable arguments when using |
This also resolves #421 as well now. |
And #420. |
geez, leave some issues for the rest of us 👍 |
Thanks for the screenshots. I can't seem to reproduce this. I've tried on my Linux laptop with Python 3.8 using both PyQt5 and PySide2, with and without an external monitor plugged into it. |
Running |
I can confirm on macOS the scatter plots behave well, as does the exporter, nice work!! I'll try to break this a bit more a little bit later today. |
#915 is also related. I treated the missing Regarding not emitting |
And another: #1118. I haven't implemented a hovering API in |
Does anyone have any thoughts about deprecating the |
I think this would be great, but I don't think this has to be part of this PR, as I anticipate merging shortly; ...
I think we should add this in, but like the previous comment, doesn't have to be part of this specific PR, but another one that addresses this specific issue. If there is any kind of potential API breakage, having it on its own PR will make it easier to track down later should there be an issue made in the future. |
This is a monster PR, thanks for your work on this @lidstrom83 now I have to go through and identify which issues/existing PRs I can close as a result 😆 merging. |
ScatterPlotItem
which lets the user specify a separate style for the hovered points and show a tool tip containing information about them. A signal is also emitted during hovering.