0

i want to ask that what is more costlier for iphone to render. a button given shadow with CALayer or button with image. now i know one button would not make any difference but what about if i have 10k records in uitableview.

IDev
  • 1,221
  • 1
  • 11
  • 25
  • 1
    It still wouldn't matter if you have 10k records in a table view because the table view only creates enough cells to fill the view and then reuses those cells. There's no difference between a table view with 5 records that fill the entire screen and 10k records. – AdamPro13 Oct 20 '20 at 17:30
  • it's incredibly unlikely it will be an issue. (Note what Adam explains.) just use shadowPath as in zillions of examples: https://stackoverflow.com/a/57465440/294884 – Fattie Oct 20 '20 at 19:19

1 Answers1

1

CALayer for shadows

I guess you are referring to the default way to creating shadows like the following by saying CALayer for shadows

layer.shadowColor = 
layer.shadowOffset =
layer.shadowOpacity =
layer.shadowRadius =   

Preparing the shadow this way is computationally expensive, since GPU needs dynamically calculate overall color and opacity of for the part of the visible screen where shadow is to be applied.

Since you are going to use this shadow in a scroll view, this calculation is to be done within 17ms to maintain a standard 60Hz refresh rate. Keep in mind that in this time you also need to made some side calculation for

  1. extracting the data model from large array.
  2. calculate other cell attributes (in case of sub-classing UICollectionViewLayout).

My suggestion will be to use

  1. shadow path
  2. use an image from asset catalog for dropping a fixed size shadow
  3. pre-render your shadow into an image and cache it to use later as a shadow.

Otherwise Debug-View may show you some warning like the following enter image description here

Optimization Opportunities: The layer is using dynamic shadows which are expensive to render. If possible try setting shadowPath, or pre-rendering the shadow into an image and putting it under the layer.

You will find more instruction from this tutorial.

Sauvik Dolui
  • 5,520
  • 3
  • 34
  • 44
  • it's done on the GPU and it's unbelievably quick. it would be a non-issue in the scenario given. – Fattie Oct 20 '20 at 19:17
  • recall too in almost all cases it will just be part of the cell and just re-used, with text etc. being changed – Fattie Oct 20 '20 at 19:20