-
Notifications
You must be signed in to change notification settings - Fork 74
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
Cubeviz slider performance improvements #1550
Conversation
Did you benchmark the improvement? |
Codecov Report
@@ Coverage Diff @@
## main #1550 +/- ##
==========================================
- Coverage 85.48% 85.44% -0.05%
==========================================
Files 93 94 +1
Lines 8749 9054 +305
==========================================
+ Hits 7479 7736 +257
- Misses 1270 1318 +48
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Just about to mark this PR as ready for review; here's all I've learned from profiling Cubeviz: There is a divide here in where I was able to profile. The front-end part which I couldn't find a way to profile details going from actual mouse click to the underlying Jdaviz code. The best way to detail this section I think came from Kyle: "This is where, for example, the browser has to wait a moment to determine if the user has double-clicked." The profiling I was able to do comes from after receiving the instruction to change wavelength, to actually changing the wavelength So after testing the two techniques for selecting the wavelength, the time it took to select 200 random wavelengths dropped from 53.577 seconds to 51.470 seconds, or an improvement of 4%. We're really scratching the bottom of the barrel here without touching the actual strategy itself (which would be more than 3 points of effort 😅. Attached below are the top calls from the profiler for 100 runs:
What's actually taking so long is the process of converting the wavelength input to an actual indexed-slice. To do this,
|
@duytnguyendtn - that is very useful investigative work! I agree that caching might be quite useful, but I'm just curious if accessing the marks object for the displayed spectrum would be sufficiently faster. Something like the following in
instead of the existing
|
@kecnry You're a genius!!!
|
Co-authored-by: Kyle Conroy <[email protected]>
Can we replace this jdaviz/jdaviz/configs/cubeviz/helper.py Lines 88 to 90 in f7ee912
with this? wavelength = wavelength * wave_unit # We store the unit somewhere, right?
index = self.app.data_collection[0].coords.spectral_wcs.world_to_pixel(wavelength) # Assume [0] is always FLUX
return self.select_slice(int(index)) The WCS is already there. The only thing I am not sure about is whether |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticeably snappier on the default cube! Thanks for tracking this down!
Ah, I just saw Kyle had the same idea but different solution. I guess that works too if we can trust the marks. |
@@ -41,8 +41,7 @@ def on_mouse_event(self, data): | |||
# throttle to 200ms | |||
return | |||
|
|||
msg = SliceSelectWavelengthMessage(wavelength=data['domain']['x'], sender=self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even need SliceSelectWavelengthMessage
with this removal? Should we remove this message from the code base altogether?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kecnry , any reason we still need to listen to SliceSelectWavelengthMessage
in app at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quickly looking through the code, and it looks like the slider was the only thing that used it? I'll remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, if its not used anywhere else, let's get rid of it here.
I think since we don't allow unloading the reference data from the UI (technically the user could manually remove it from the API), then the marks should be reliable. But trying both and seeing which performs better never hurts! For the marks approach, it might eventually be worth caching the marks entry so we don't have to do that ugly loop to find it though... |
@@ -85,7 +85,10 @@ def select_wavelength(self, wavelength): | |||
wavelength = float(wavelength.wavelength) | |||
if not isinstance(wavelength, (int, float)): | |||
raise TypeError("wavelength must be a float or int") | |||
x_all = self.app.get_viewer('spectrum-viewer').data()[0].spectral_axis.value | |||
# Retrieve the x slices from the spectrum viewer's marks | |||
x_all = [m for m in self.app.get_viewer('spectrum-viewer').figure.marks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not familiar with marks. Is it always in the unit we think it is in, especially with all the unit conversion going on via plugin, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the marks are in the plotted units, the click/drag even is guaranteed to be in plotted units, and the select_wavelength
method says that it assumes the user input for wavelength is provided in plotted units, so I think we're safe (for now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the marks will always be in the same units of the spectrum viewer, since they are the literal marks that are plotted on screen. When using the slice tool, it will naturally request the wavelength in units of the viewer it's acting on, so I think that should be consistent? @kecnry is that a fair statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's fair. The only possible problem I can see would be when the user calls the API manually, but the API docs state that no unit conversion is done, so I think that can be kicked down the road for the unit conversion refactor (if at all)
This is basically a performance bug fix, so I think we need a change log. |
Co-authored-by: P. L. Lim <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
Description
This PR attempts to improve the performance of the cubeviz slider by using the helper rather than passing messages around.
Checklist for package maintainer(s)
This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.
trivial
label.CHANGES.rst
?