-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
MNT: Reduce number of calls to _update #9407
MNT: Reduce number of calls to _update #9407
Conversation
Notebook test is failing, seems related. In any case, this is the slowest
and on
So not a huge difference. Do you notice any timing difference locally @GuillaumeFavelier ? It might be the case that calling
and I see "up" printed a bunch and get the same FPS in both cases -- it's low on my laptop, like 3, so if it's actually re-rendering each time it seems like it should drop to updating less than once a minute. So I'm not sure this will gain us too much? On the other hand, if setting the camera forces a re-render somehow at the PyVista end (by doing a .Render call directly rather than plotter.update() maybe?) -- which seems possible since sometimes the brains switch views? Might also be worth checking the logic in their update method to understand things if you haven't already (I had a quick look and don't fully understand the logic): https://github.com/pyvista/pyvista/blob/master/pyvista/plotting/plotting.py#L986-L1012 |
Locally, the average of 10 calls for
The impact is limited to say the least. I won't lie, this |
VTK might also be smart enough internally to figure out if anything in the scene has changed, so even if you In any case, worth looking into! |
Because of the inheritance of
It is probably a Qt or VTK function 😅 |
I verified and:
So I think (by elimination) that it's from This would explain why |
Since this is clarified, I'll revert and I'll switch to the second part of the PR namely minimizing the number overlay updates. There is not much I can do for the first part except maybe minimizing the number of calls to |
This reverts commit 5bf39ff.
One thing I've noticed is slow is loading the window in the first place. I would start by making a script that just loads and closes maybe 10 times, |
The latest commit 8067b94 drastically improves the caching system of overlays:
I also updated the tests. I think it can be improved further but a complexity analysis would probably be necessary to evaluate if it's worth or not. |
I'll investigate #9407 (comment) next |
Using
Conclusion: Interfacing with Scriptimport os
import mne
from mne.datasets import sample
data_path = sample.data_path()
sample_dir = os.path.join(data_path, 'MEG', 'sample')
subjects_dir = os.path.join(data_path, 'subjects')
fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')
stc = mne.read_source_estimate(fname_stc, subject='sample')
initial_time = 0.096
for i in range(10):
brain = stc.plot(
subjects_dir=subjects_dir, initial_time=initial_time,
clim=dict(kind='value', lims=[3, 6, 9]),
size=600,
hemi='rh',
views=['lat', 'med'],
)
brain.close() |
Looks like a big target is |
Yes, you are right it takes all the time |
Using
Scriptimport os
import mne
from mne.datasets import sample
data_path = sample.data_path()
sample_dir = os.path.join(data_path, 'MEG', 'sample')
subjects_dir = os.path.join(data_path, 'subjects')
fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')
stc = mne.read_source_estimate(fname_stc, subject='sample')
initial_time = 0.096
for i in range(10):
brain = stc.plot(
subjects_dir=subjects_dir, initial_time=initial_time,
clim=dict(kind='value', lims=[3, 6, 9]),
size=600,
hemi='rh',
show_traces=False,
views=['lat', 'med'],
)
brain.close() |
Using
Scriptimport os
import mne
from mne.datasets import sample
data_path = sample.data_path()
sample_dir = os.path.join(data_path, 'MEG', 'sample')
subjects_dir = os.path.join(data_path, 'subjects')
fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')
stc = mne.read_source_estimate(fname_stc, subject='sample')
initial_time = 0.096
for i in range(10):
brain = stc.plot(
subjects_dir=subjects_dir, initial_time=initial_time,
clim=dict(kind='value', lims=[3, 6, 9]),
size=600,
hemi='rh',
time_viewer=False,
show_traces=False,
views=['lat', 'med'],
)
brain.close() |
After 0a31936, the average of 3 x 10 runs:
import os
import time
import mne
from mne.datasets import sample
data_path = sample.data_path()
sample_dir = os.path.join(data_path, 'MEG', 'sample')
subjects_dir = os.path.join(data_path, 'subjects')
fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')
stc = mne.read_source_estimate(fname_stc, subject='sample')
initial_time = 0.096
start_time = time.time()
for i in range(10):
brain = stc.plot(
subjects_dir=subjects_dir, initial_time=initial_time,
clim=dict(kind='value', lims=[3, 6, 9]),
size=600,
hemi='rh',
views=['lat', 'med'],
)
brain.close()
current_time = time.time()
elapsed_time = current_time - start_time
print("Finished iterating in: " + str(int(elapsed_time)) + " seconds") Using
Using
|
Same observation as #9407 (comment), interfacing with What I can say is that any significant improvement to |
This PR is ready for reviews on my end @larsoner |
|
@GuillaumeFavelier I pushed a commit that uses |
(my changes optimize |
After 9931f38, the average of 3 x 10 runs:
It feels way better in my opinion so I am happy with those changes :) The failure of |
Probably |
Thanks @GuillaumeFavelier ! |
A couple of nice things testing-wise, on another PR that ran recently we had:
and on the last run for this PR it was:
|
* upstream/main: [MRG] change utils.logger.warning -> utils.warn (mne-tools#9434) FIX : rank computation from info now uses SSS proc history if only grad or mag are present (mne-tools#9435) MRG: Enable interpolation for all fNIRS types (mne-tools#9431) FIX: brain save_movie (mne-tools#9426) ENH: Add mne.export (mne-tools#9427) ENH: Test more on pre [skip circle] (mne-tools#9423) MRG, ENH: Speed up brain test (mne-tools#9422) MAINT: Update URL [ci skip] MNT: Reduce number of calls to _update (mne-tools#9407) MRG: Tutorial improvements (mne-tools#9416)
This PR reduces the amount of renderer updates. I modified the two main entry points:
__init__()
andsetup_time_viewer()
.For now I use a context manager but if big chunks of code need to be nested maybe
enable/disable
functions are better, not sure.I'm still trying to download 0.119 locally so testing is delayed but in the example that I use regularly, it went from 16 to 1.
I'll see how to reduce the amount of overlay updates next.
I'll also investigate why the window is so slow to setup (suggested in MNT: Reduce number of calls to _update #9407 (comment))
Closes #8986