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

performance: use clip-path css instead of width #1983

Merged
merged 7 commits into from
Jun 30, 2020

Conversation

osheroff
Copy link
Contributor

constantly changing the width of the multi-canvas progressWave element triggers a layout pass in the browser. This doesn't seem to be a huge problem for Chrome, but in Safari on mac it's worth quite a hunk of performance.

This is Safari pre-patch (I played the whole file on /example/html-init/ for these tests):

Screen Shot 2020-06-23 at 9 17 18 PM

Safari post-patch:

Screen Shot 2020-06-23 at 9 15 15 PM

Chrome seems to jitter more and benefit less, but note the ~10% of rendering that we seem to save:

pre-patch:
Screen Shot 2020-06-23 at 9 28 19 PM
Screen Shot 2020-06-23 at 9 29 08 PM

post-patch:
Screen Shot 2020-06-23 at 9 30 35 PM
Screen Shot 2020-06-23 at 9 31 30 PM

would love to know if I'm missing anything with the logic here or if other people can run benchmarks and see if this feels like a win.

this prevents browsers from continuously making layout engine passes.
@coveralls
Copy link

coveralls commented Jun 24, 2020

Coverage Status

Coverage increased (+0.06%) to 80.567% when pulling c86db5b on osheroff/clip_path into 4cb1fe1 on master.

Copy link
Owner

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!
Could you replace string concatenation with template strings? And the remaining double quotes with single ones.

@marizuccara
Copy link
Contributor

marizuccara commented Jun 25, 2020

Tried in Chrome/Windows and it works correctly. I have not Safari, so I cannot see the performance there. But this improvement seems to have sense, so I approve

Copy link
Contributor

@thijstriemstra thijstriemstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a changelog entry, but other than that, LGTM.

src/drawer.multicanvas.js Show resolved Hide resolved
@osheroff
Copy link
Contributor Author

ok, all fixed. @katspaugh is this part of the officially required style for the project (template strings over concatenation, single quotes")? could this be in es-lint rather than a round-trip on every PR?

@katspaugh
Copy link
Owner

Thanks, @osheroff!
It would be great to add these rules to the eslint config, yes. There might be a few places where we had used concatenation though.

CHANGES.md Outdated Show resolved Hide resolved
@thijstriemstra thijstriemstra changed the title use clip-path css instead of width performance: use clip-path css instead of width Jun 27, 2020
@thijstriemstra thijstriemstra merged commit 0fec788 into master Jun 30, 2020
@thijstriemstra thijstriemstra deleted the osheroff/clip_path branch June 30, 2020 16:20
osheroff added a commit that referenced this pull request Jul 5, 2020
this killed off the cursor functionality.  we're using the
right-hand-border of the progressWave to show a "audio cursor" element.
osheroff added a commit that referenced this pull request Jul 6, 2020
this killed off the cursor functionality.  we're using the
right-hand-border of the progressWave to show a "audio cursor" element.
sandiz pushed a commit to sandiz/wavesurfer.js that referenced this pull request Sep 1, 2021
* use a clip-path css mask instead of changing width

this prevents browsers from continuously making layout engine passes.

* code review fixes; code style, comments

* add changelog entry

* add PR number to changelog

Co-authored-by: Thijs Triemstra <info@collab.nl>
sandiz pushed a commit to sandiz/wavesurfer.js that referenced this pull request Sep 1, 2021
…)" (katspaugh#1994)

this killed off the cursor functionality.  we're using the
right-hand-border of the progressWave to show a "audio cursor" element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants