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

lag when redrawing >300 strokes. #4

Open
8gb opened this issue Dec 6, 2021 · 6 comments
Open

lag when redrawing >300 strokes. #4

8gb opened this issue Dec 6, 2021 · 6 comments
Assignees

Comments

@8gb
Copy link

8gb commented Dec 6, 2021

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 8gb changed the title handwriting not registered when redrawing >300 strokes. lag when redrawing >300 strokes. Dec 6, 2021
@collinzrj collinzrj self-assigned this Dec 6, 2021
@collinzrj
Copy link
Owner

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.

@8gb
Copy link
Author

8gb commented Dec 7, 2021

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.

@collinzrj
Copy link
Owner

Thanks, I will study it soon

@collinzrj
Copy link
Owner

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.

@8gb
Copy link
Author

8gb commented Dec 10, 2021

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!

@collinzrj
Copy link
Owner

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.

Repository owner deleted a comment from crydra Feb 23, 2024
@github-staff github-staff deleted a comment from maulanaayub May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants