Bug 146345

Summary: Make JS & SVG animation faster
Product: WebKit Reporter: Tobi Reif <tobi>
Component: SVGAssignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Normal CC: simon.fraser, tobi, webkit-bug-importer, zimmermann
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
URL: http://codepen.io/TobiReif/pen/15e6a50df654f594ff2f845d0c649397
Attachments:
Description Flags
Screenshot of https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ in Safari 11.0 (12604.1.38.1.7) plus timeline.
none
Safari FPS timeline for https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/
none
Framerate in Safari of https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ none

Tobi Reif
Reported 2015-06-26 06:06:34 PDT
In my current project I animate SVG using JS (JS animation crystallized as the best option). I do ".setAttribute("transform", ...)" or ".setAttribute("x", ...)" (in a requestAnimationFrame loop) to move hundreds of small images fast across the screen (also rotation and alpha). There might be room for improvement regarding performance; perhaps WebKit/Safari could do as much as possible in the GPU.
Attachments
Screenshot of https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ in Safari 11.0 (12604.1.38.1.7) plus timeline. (680.87 KB, image/png)
2017-10-19 02:47 PDT, Tobi Reif
no flags
Safari FPS timeline for https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ (771.97 KB, image/png)
2017-12-06 02:22 PST, Tobi Reif
no flags
Framerate in Safari of https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ (10.26 KB, image/png)
2021-07-12 02:40 PDT, Tobi Reif
no flags
Tobi Reif
Comment 1 2016-02-16 04:22:17 PST
... and perhaps there are additional options for making JS-animated SVG perform really well (e.g. as fast as PixiJS).
Tobi Reif
Comment 2 2016-05-10 02:28:27 PDT
1) Something like Mozilla Servo might be useful as inspiration. 2) Here's a test case: https://twitter.com/TobiReif/status/725611064973479936 https://twitter.com/TobiReif/status/725611198847311874
Simon Fraser (smfr)
Comment 3 2016-05-10 13:42:59 PDT
Simon Fraser (smfr)
Comment 4 2016-05-10 13:47:59 PDT
Some brief profiling shows: 32% under WebCore painting, mostly in ellipse filling 20% under layout, most of which is computing repaint rects 6.5% under Element::setAttribute(), mostly in parsing
Tobi Reif
Comment 5 2017-10-17 04:14:00 PDT
I hope the performance of WebKit regarding eg https://tobireif.com/non_site_stuff/svg_perf_tests/animated-dots-in-svg/ can be improved.
Simon Fraser (smfr)
Comment 6 2017-10-17 08:30:33 PDT
https://tobireif.com/non_site_stuff/svg_perf_tests/animated-dots-in-svg/ gets 60fps on an old MacBook Air. Seems reasonable?
Tobi Reif
Comment 7 2017-10-19 02:45:09 PDT
Sounds good! It is not 100.00% smooth to my eyes, but that's hard to measure. Now on to a more challenging JS & SVG animation 😀 Please check out Safari's perf regarding https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ Please also see the screenshot "screenshot_of_animated_snake_pattern_plus_timeline.png" of that demo being measured in Safari Version 11.0 (12604.1.38.1.7). I hope that WebKit can be improved to run this animation (and other demanding SVG & JS animations) smoothly.
Tobi Reif
Comment 8 2017-10-19 02:47:25 PDT
Simon Fraser (smfr)
Comment 9 2017-10-31 13:14:53 PDT
I get 60fps on https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ on a Mac Pro. The slowest part is running the script which is modifying SVG attributes (about 14ms per frame). Painting only takes about 3-4ms.
Tobi Reif
Comment 10 2017-11-02 02:01:03 PDT
I'm on a Mid 2015 MacBook Pro, and the visual performance of that animation in Safari is not completely & constantly smooth. Also see the dev tools screenshot https://bug-146345-attachments.webkit.org/attachment.cgi?id=324214 . It would be important to test the animation on an iPhone as well, perhaps you could do that? In the meantime here's a video created using CrossBrowserTesting: https://app.crossbrowsertesting.com/public/ib8393c20a124bac/livetests/9488261/videos/z2cc3f514d58872ec6b8 You wrote: "The slowest part is running the script which is modifying SVG attributes (about 14ms per frame)." The animation uses GSAP TweenMax, I hope that code is fast. Perhaps running the JS which is modifying SVG attributes could be done faster by WebKit?
Simon Fraser (smfr)
Comment 11 2017-11-02 08:24:21 PDT
(In reply to Tobi Reif from comment #10) > The animation uses GSAP TweenMax, I hope that code is fast. That part you could profile yourself by looking at the JS profile in the web inspector.
Tobi Reif
Comment 12 2017-11-05 01:36:13 PST
This is the complete animation code from https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ : function stagger() { var distance = 70; TweenMax.staggerFromTo( "use", 0.5, {y: -distance}, { y: distance, ease: Sine.easeInOut, yoyo: true, repeat: -1 }, 0.001 ); } I wish I had the time to profile GSAP TweenMax and see whether their code could be made faster. But I'll have to leave that up to them (the commercial vendor Greensoock https://greensock.com/club ). GSAP is "the industry standard". Mmany people and companies use GSAP, it's very popular. So it would sure be worth the effort to investigate whether WebKit can run GSAP TweenMax (used with SVG eg as above) faster. If the improvements are general they will potentially benefit all JS-SVG animations. "The slowest part is running the script which is modifying SVG attributes (about 14ms per frame)" - I hope that this duration can be improved significantly.
Tobi Reif
Comment 13 2017-12-06 02:17:35 PST
Also, Safari uses ~80% CPU (on a MacBook Pro "Retina, 15-inch, Mid 2015" == 2.5 years old). It seems Safari should instead use the GPU (for as much as possible).
Tobi Reif
Comment 15 2017-12-06 02:24:10 PST
On a MacBook Pro "Retina, 15-inch, Mid 2015" (== 2.5 years old), Safari's dev tools show a framerate timeline way below 60 FPS, please see the attached screenshot "screenshot_safari_fps.png". I hope you can ensure 100% smooth animation.
Simon Fraser (smfr)
Comment 16 2017-12-06 10:06:51 PST
Safari is using the GPU for rendering, but there's a lot of CPU work that also has to happen.
Tobi Reif
Comment 17 2017-12-07 01:57:17 PST
I see, thanks for the info! I hope you can ensure smooth animation / 60 FPS https://bug-146345-attachments.webkit.org/attachment.cgi?id=328561 no matter how 😀
Radar WebKit Bug Importer
Comment 18 2017-12-07 15:08:04 PST
Tobi Reif
Comment 19 2021-07-09 06:58:18 PDT
This demo https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ doesn't run smoothly in Safari. I hope this can get fixed soon.
Simon Fraser (smfr)
Comment 20 2021-07-09 09:18:20 PDT
(In reply to Tobi Reif from comment #19) > This demo > https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my- > snake-pattern-in-svg/ > doesn't run smoothly in Safari. I hope this can get fixed soon. On what OS/hardware configuration?
Tobi Reif
Comment 21 2021-07-12 02:29:41 PDT
> On what OS/hardware configuration? MacOS 11.4 (20F71) MacBook Pro (16-inch, 2019) 2,6 GHz 6-Core Intel Core i7 32 GB 2667 MHz DDR4 AMD Radeon Pro 5300M 4 GB Intel UHD Graphics 630 1536 MB
Tobi Reif
Comment 22 2021-07-12 02:40:21 PDT
Created attachment 433307 [details] Framerate in Safari of https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ Except for the first single bar in the screenshot, the framerate is consistently below 60 fps. It seems to be around 40 fps. It would be great if it would always be at or above 60 fps.
Tobi Reif
Comment 23 2022-11-16 03:09:06 PST
The animations https://tobireif.com/non_site_stuff/just-a-perf-test-animated-fork-of-my-snake-pattern-in-svg/ and https://tobireif.com/non_site_stuff/svg_perf_tests/animated-dots-in-svg/ now seem to run quite smoothly. Yay! Thanks! I tested on a MacBook Pro (16-inch, 2019, 2,6 GHz 6-Core Intel Core i7, 32 GB 2667 MHz DDR4, AMD Radeon Pro 5300M 4 GB, Intel UHD Graphics 630 1536 MB, MacOS 12.6) (Safari 16.0 (17614.1.25.9.10, 17614)).
Note You need to log in before you can comment on or make changes to this bug.