Skip to content
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

Hold streams together for faster plot callbacks #6247

Closed
wants to merge 5 commits into from
Closed

Conversation

ahuang11
Copy link
Collaborator

Philipp suggested this; not sure if the following is necessary:

                if self.plot.comm:
                    push_on_root(self.plot.root.ref['id'])

@ahuang11 ahuang11 requested a review from philippjfr May 24, 2024 18:18
@ahuang11 ahuang11 changed the title Hold streams together for faster plotting Hold streams together for faster plot callbacks May 24, 2024
Copy link

codecov bot commented May 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.47%. Comparing base (2ba3d78) to head (1afb3a8).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6247      +/-   ##
==========================================
+ Coverage   88.39%   88.47%   +0.08%     
==========================================
  Files         323      323              
  Lines       67620    67642      +22     
==========================================
+ Hits        59770    59849      +79     
+ Misses       7850     7793      -57     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ahuang11
Copy link
Collaborator Author

I tried this too, but I'm not sure why self.plot.root is a Row instead of a bokeh figure

            with self.plot.root.hold_render():
                with set_curdoc(self.plot.document):
                    Stream.trigger(streams)

@philippjfr
Copy link
Member

but I'm not sure why self.plot.root is a Row instead of a bokeh figure

The root is the Bokeh root on the Bokeh document and will change depending on whether you are rendering the plot on its own or inside some Panel component.

@philippjfr
Copy link
Member

I'd suggest using:

            with self.plot.state.hold_render():

@hoxbro hoxbro added this to the 1.19.0 milestone May 30, 2024
@hoxbro hoxbro added the type: enhancement Minor feature or improvement to an existing feature label May 30, 2024
@philippjfr
Copy link
Member

@ahuang11 Can you confirm whether this still gives the expected speedups?

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Jun 4, 2024

It seems so.

This is self.plot.state.hold_render(B)

b.mp4

And this is self.plot.document.hold() (A, original)

a.mp4

hold_render (B) seems to do it in batches, and potentially seem a little faster because upon wheel zoom, it throttles vs non-throttle. I do like how (A) updates each line individually for a sense of progress.

@ahuang11 ahuang11 requested a review from philippjfr June 4, 2024 14:23
@ahuang11
Copy link
Collaborator Author

ahuang11 commented Jun 4, 2024

Seems like it works in notebook (VSCode)

c.mp4

@philippjfr
Copy link
Member

That looks much slower than what we saw originally, no?

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Jun 4, 2024

We previewed it on @droumis 's machine last time. Also, not sure if he used the same resampled data tree as me.

A is the "original" method.

@droumis
Copy link
Member

droumis commented Jun 5, 2024

Seeing 2:4 second lag on my end for render updates for this self.plot.state.hold_render approach. I'm also including in here Philipp's fix to the rangetoolink to work with subcoordinate_y.

I'm not seeing the blanking when box-zooming, but I'm also not subselecting channels based on the viewport, just time slicing. Andrew, can you show me your channel-slicing approach? Here's the version of the code I used for this.

video2300728378.mp4

What was the code block we initially saw very good speed with? I'll try that again too

@droumis
Copy link
Member

droumis commented Jun 5, 2024

What was the code block we initially saw very good speed with? I'll try that again too

Assuming the 'original' code block was the following

                self.plot.document.hold()
                try:
                    Stream.trigger(streams)
                finally:
                    self.plot.document.unhold()

With the original approach, I'm seeing slightly faster times, ~1-3 seconds for updates (also, still not channel slicing):

video2602508095.mp4

@philippjfr
Copy link
Member

Someone should dig into this with the browser performance profiler like we did last time to see what it's doing while you wait for the update.

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Jun 5, 2024

I'd define channel_slice like this:


    channel_slice = slice(y_range[0], y_range[1])

    # calculate the appropriate pyramid level and


    ...
    # extract new data and re-paint the plot
    ds = _extract_ds(ts_dt, pyramid_level, channels).sel(time=time_slice, channel=channel_slice).load()

    ...
    for channel in ds["channel"].values.tolist():

@droumis
Copy link
Member

droumis commented Jun 5, 2024

Ok, I've added the channel slicing. The performance is better now all around, even without holding the render. But now I'm seeing a lot of fragility with the channel y-ticks while navigating around.. e.g.:

image

@ahuang11 , do you see this as well? Is it the same thing as mentioned here?

@droumis
Copy link
Member

droumis commented Jun 5, 2024

Initial Profiling:

Baseline (with channel slicing, no render holding):
baseline_no-hold.mp4
plot.document.hold
plot.document.hold.mp4
plot.state.hold_render

Sometimes can take very long to update, other times very quick

plot.state.hold_render.mp4

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Jun 5, 2024

@ahuang11 , do you see this as well? Is it the same thing as mentioned #6256 (comment)?

Yes that's the same issue.

Thanks for doing the profiling!

@philippjfr
Copy link
Member

Closing in favor of #6265

@philippjfr philippjfr closed this Jun 6, 2024
@hoxbro hoxbro deleted the hold_streams branch June 6, 2024 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants