Shadow performance? #773
Replies: 3 comments 3 replies
-
Asked a related question as I was playing with this on the issues page (sorry!) |
Beta Was this translation helpful? Give feedback.
-
Indeed the perf monitor doesn't give accurate values since we execute things outside the JS and the UI thread. We found that using masking operation even on the GPU are quite slow, especially on Android devices. Some of the best practices there we took from the google chrome implementation (regarding inner shadows for instance). Can you try to use a drop shadow instead of a MaskBlur? |
Beta Was this translation helpful? Give feedback.
-
A drop shadow seems quicker — but still drops the frame rate visibly. Do you think this improve over time, or is it already as optimised as it'll ever be? For others, the paint operation goes something like this (if I've understood it correctly):
|
Beta Was this translation helpful? Give feedback.
-
Hi!
I'm trying to create a virtualized graph renderer, and as such I need to re-paint everything on scroll.
Scrolling is done using a reanimated2 pan recogniser, and later it will feature tapping, pinching and more.
The reanimated value is then translated to a Skia transform, which is applied as a
translateX
on a top levelGroup
.This
translateX
is calculated with:[{ translateX: skiaTranslateX.current % 50 }]
, where 50 is the width of a single bar.I also shift the data to be rendered with
% 50
, so it looks like a scrolling list but only the visible parts on screen are being rendered.This means that on every single scroll I re-paint the entire screen (which is just ~ 500x400 depending on device).
The painting is done using a
<Drawing />
component. Let's say that each bar just consists of a vertical line, and a filled bar.So far it renders at 60 FPS when scrolling, even on a slow Android device!
But if I add a shadow behind each bar then it drops to 15-20 FPS on a slow Android device. On iOS (iPhone 12 Pro) it's 60 FPS and buttery smooth. The RN perf monitor says 60 for both UI and JS on both platforms, but it's far from true on the Android.
The shadow is drawn using some code found in
Box
:paint
is defined globally as it never changes, like soI would very much like to use shadows, are there any performance tricks I could apply?
Any change in approach? Could it be faked with an image?
What is actually taking up render time here? Is it the blue operation? Can the quality be lowered to make it faster?
Even if I pre-render a 3000+ px wide Skia Canvas and scroll using a native ScrollView the performance isn't enough, again on a slow Android. On iOS it is decent, but with the virtualised approach it is 60 FPS buttery smooth even with shadows.
Ciao,
Erik
Beta Was this translation helpful? Give feedback.
All reactions