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

Improve rendering performance when pxPerSec is high #909

Merged
merged 1 commit into from
Jan 16, 2017

Conversation

elijah-taylor
Copy link

  • Adds an optional 'partialRender' parameter to enable
  • Calculates and renders peaks only for current visible waveform
  • Keeps track of currently calculated/rendered peaks to avoid
    duplicate calculation and only incremental scroll changes are rendered

Tested all combinations of Canvas/MultiCanvas and Wave/Bars rendering
at various zoom levels.

* Adds an optional 'partialRender' parameter to enable
* Calculates and renders peaks only for current visible waveform
* Keeps track of currently calculated/rendered peaks to avoid
  duplicate calculation and only incremental scroll changes are rendered

Tested all combinations of Canvas/MultiCanvas and Wave/Bars rendering
at various zoom levels.
@katspaugh katspaugh merged commit 3d908c5 into katspaugh:master Jan 16, 2017
@katspaugh
Copy link
Owner

Thanks a lot! Sorry it took so long to merge!

@swampthang
Copy link

Awesome work! Thanks for adding this. Is this gonna make its way into the npm version? Working in nodejs and have to work using PC and Mac so need to be able to update via npm.

@katspaugh
Copy link
Owner

I'm waiting for feedback in the last open PR and will release afterwards.

@swampthang
Copy link

ok, thanks.

@swampthang
Copy link

swampthang commented Jan 17, 2017

Question on this. Should this resolve an issue I have where the waveform disappears when the pxsPerSec value is above 260? Using zoom(270)
Update: Nevermind. Just realized this was a browser limitation. Set renderer to 'MultiCanvas' and it fixed that issue. Thanks again for an awesome library.

@elijah-taylor
Copy link
Author

(wrote this before your edit) I think the waveform disappearing with zooming is a limitation of single canvas. Probably the internal representation of your canvas is > 4000px or whatever the size limitation of canvas is on your particular browser's/gpu's implementation. This PR will not fix that, because the canvas allocation will still fail. You should try multi-canvas to address this, but now this PR will mean that you won't over-render to the whole multi-canvas when the option is set.

I've used zoom levels well above 270 in my test app, I think into the thousands.

IMO multi-canvas should be the default and you should consider removing single-canvas because it's strictly a subset of the functionality of multi-canvas.

@katspaugh
Copy link
Owner

I've made MultiCanvas the default renderer and published version 1.3.0 on npm. Thanks everyone!

mspae pushed a commit to mspae/wavesurfer.js that referenced this pull request Jan 20, 2017
* Adds an optional 'partialRender' parameter to enable
* Calculates and renders peaks only for current visible waveform
* Keeps track of currently calculated/rendered peaks to avoid
  duplicate calculation and only incremental scroll changes are rendered

Tested all combinations of Canvas/MultiCanvas and Wave/Bars rendering
at various zoom levels.
thijstriemstra pushed a commit that referenced this pull request Jan 27, 2017
…is high (#909) (#924)

* Improve rendering performance when pxPerSec is high (#909)

* Adds an optional 'partialRender' parameter to enable
* Calculates and renders peaks only for current visible waveform
* Keeps track of currently calculated/rendered peaks to avoid
  duplicate calculation and only incremental scroll changes are rendered

* Tested all combinations of Canvas/MultiCanvas and Wave/Bars rendering
at various zoom levels.

* travis with prune for more accurate dependency resolution

* updated karma-webpack to work with webpack 2
tf added a commit to tf/wavesurfer.js that referenced this pull request Jun 19, 2017
refs katspaugh#1127

Before katspaugh#909, calling `drawBuffer` to redraw the wave invoked
`drawer.drawPeaks` which in turn invoked `drawer.setWidth` which
always caused the canvas to be cleared as a side effect of
`drawer.updateSize`.

In katspaugh#909 `setWidth` was changed to short circuit if the width did not
change. This now causes the waveform to be redrawn on top of the
previous rendition, making the edges of the wave appear less crisp.

This change makes `setWidth`/`setHeight` return a boolean to indicate
whether changes were needed. If not, `drawer.clearWave` is called
manually. So we make sure that the previous wave is always cleared,
but do not perform the possibly performance intensive task of clearing
the canvas twice if it already happened as a side effect of
`setWidth`.
katspaugh pushed a commit that referenced this pull request Jul 2, 2017
refs #1127

Before #909, calling `drawBuffer` to redraw the wave invoked
`drawer.drawPeaks` which in turn invoked `drawer.setWidth` which
always caused the canvas to be cleared as a side effect of
`drawer.updateSize`.

In #909 `setWidth` was changed to short circuit if the width did not
change. This now causes the waveform to be redrawn on top of the
previous rendition, making the edges of the wave appear less crisp.

This change makes `setWidth`/`setHeight` return a boolean to indicate
whether changes were needed. If not, `drawer.clearWave` is called
manually. So we make sure that the previous wave is always cleared,
but do not perform the possibly performance intensive task of clearing
the canvas twice if it already happened as a side effect of
`setWidth`.
mspae pushed a commit to mspae/wavesurfer.js that referenced this pull request Aug 18, 2017
refs katspaugh#1127

Before katspaugh#909, calling `drawBuffer` to redraw the wave invoked
`drawer.drawPeaks` which in turn invoked `drawer.setWidth` which
always caused the canvas to be cleared as a side effect of
`drawer.updateSize`.

In katspaugh#909 `setWidth` was changed to short circuit if the width did not
change. This now causes the waveform to be redrawn on top of the
previous rendition, making the edges of the wave appear less crisp.

This change makes `setWidth`/`setHeight` return a boolean to indicate
whether changes were needed. If not, `drawer.clearWave` is called
manually. So we make sure that the previous wave is always cleared,
but do not perform the possibly performance intensive task of clearing
the canvas twice if it already happened as a side effect of
`setWidth`.
mspae pushed a commit that referenced this pull request Aug 19, 2017
refs #1127

Before #909, calling `drawBuffer` to redraw the wave invoked
`drawer.drawPeaks` which in turn invoked `drawer.setWidth` which
always caused the canvas to be cleared as a side effect of
`drawer.updateSize`.

In #909 `setWidth` was changed to short circuit if the width did not
change. This now causes the waveform to be redrawn on top of the
previous rendition, making the edges of the wave appear less crisp.

This change makes `setWidth`/`setHeight` return a boolean to indicate
whether changes were needed. If not, `drawer.clearWave` is called
manually. So we make sure that the previous wave is always cleared,
but do not perform the possibly performance intensive task of clearing
the canvas twice if it already happened as a side effect of
`setWidth`.
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.

None yet

3 participants