FastDraw icon indicating copy to clipboard operation
FastDraw copied to clipboard

lag when redrawing >300 strokes.

Open 8gb opened this issue 4 years ago • 6 comments

Hi, first and foremost I love your project.

I faced an issue where the drawboard becomes laggy when it has to render more than 300 strokes. At 1900 strokes, The drawboard is basically lagging one stroke behind, stroke data such as stroke points and width are not fully captured as well.

I found the culprit to be self.setNeedsDisplay(). It will redraw the whole canvas after each stroke, which after 1900 strokes, it would take 1 seconds to complete the repaint, which is unusable for handwriting.

Few ideas on top of my mind:

  • Limit the redraw scope to the area of the new stroke.
  • Draw to CALayers
  • Caching?

Thanks!

8gb avatar Dec 06 '21 06:12 8gb

Thanks for supporting FastDraw! What device are you testing on? Is that a simulator or a real device? I have also noticed the problem but it is not obvious when when there are less than thousands of strokes. It is a good idea to limit redraw scope to the area of the new stroke, I will be working on that later. According to Draw to CALayers, actually maintaining hundreds of CALayers is a huge cost for iOS, I have tried that solution and it did not work well. Moreover, I am planning to provide a stress test function in the FastDrawDemo.

collinzrj avatar Dec 06 '21 21:12 collinzrj

I test it on physical iPad Pro M1 with Apple Pencil. This problem is obvious with fast handwriting using pencil.

I also notice the real device CPU and Memory usage is low even though the rendering issue is significant at thousands strokes.

Another question is: If CALayers is not ideal, is there any way to make this scalable to, say, 1 million strokes?

Thanks again and I looks forward to your update.

8gb avatar Dec 07 '21 06:12 8gb

Thanks, I will study it soon

collinzrj avatar Dec 07 '21 22:12 collinzrj

Hi, I am also testing on physical iPad Pro M1 with Apple Pencil, and it seems that I arrive at similar conclusion to yours. I have generated 300 strokes each with 100 UIBeziercurves (which is 30000 beziercurves in total), and the redraw time becomes 0.2 seconds, generally a redraw time below 0.1 second is unnoticeable. However, usually people do not draw strokes with 100 UIBezierCurves, so I think it can supports around 2000 curves for daily use. I am planning to do more testing on other devices, I will let you know when I have more information.

collinzrj avatar Dec 08 '21 17:12 collinzrj

Hi, I am also testing on physical iPad Pro M1 with Apple Pencil, and it seems that I arrive at similar conclusion to yours. I have generated 300 strokes each with 100 UIBeziercurves (which is 30000 beziercurves in total), and the redraw time becomes 0.2 seconds, generally a redraw time below 0.1 second is unnoticeable. However, usually people do not draw strokes with 100 UIBezierCurves, so I think it can supports around 2000 curves for daily use. I am planning to do more testing on other devices, I will let you know when I have more information.

I was using FastDraw to implement a handwriting note app. When I wrote 300~ words, the stroke count is around 2000. Assuming 3 curves per stroke, that is 6000 curves. The canvas is basically sluggish at this point.

300 handwritten words takes up roughly half of virtual A4 paper.

I hope this gives you a better context about my specific use case, and whether it has hit the library's intended limitation.

Thanks!

8gb avatar Dec 10 '21 09:12 8gb

Usually a stroke takes more than 3 curves, it is about 10 in common. I think that might be the problem, I will work on improving the performance asap.

collinzrj avatar Dec 10 '21 14:12 collinzrj