How to limit memory usage for SkPaths

168 views
Skip to first unread message

Daljit

unread,
Dec 30, 2021, 8:07:08 PM12/30/21
to skia-discuss
Hi, I've been using Skia (OpenGL backend) in my project and I've run into a high memory usage problem. My app needs to display ink strokes (ala OneNote) and the user is able to scale the ink strokes using pinch zoom or their mouse wheel.  
To draw the paths, in each frame I construct a SkPath (a filled polyline) for each stroke, scale the canvas, draw and flush. The problem is that if the user pinches in and out continuously, the app results in an almost ever growing usage of memory. Profiling in Visual Studio, having a single filled SkPath on the canvas and scaling the canvas each frame by pinching in and out, my app can easily exceeds 400-500 Mb of memory used. The bigger issue is that this memory is not immediately released on the next frame (it seems that to (slowly) release it I have to render the frame again with no draw commands for an extended period of time or commands that do not draw the same path).

I assume this is because Skia does some sort of caching of paths (at each scale I assume) and "cleverly" reuse them if needed, however I need the memory footprint to be low as at any moment in time I can
have hundrededs of strokes on the screen.
 
What I've tried so far without success:
  1.  Use SkPath::reset() after I draw the path
  2.  GrDirectContext::setResourceCacheLimit(10000)
  3.  Calling GrDirectContext::freeGpuResources() at the end of each frame.

Any suggestions to mitigate this would be appreciated.

Sherlock Doyle

unread,
Dec 31, 2021, 1:12:11 AM12/31/21
to skia-discuss

Daljit

unread,
Dec 31, 2021, 5:23:03 AM12/31/21
to skia-discuss
Making the paths volatile does not help, unfortunately. What I have noticed, this problem is most relevant when I draw filled paths (drawing stroked paths, the memory usage seems to be more stable).

Sherlock Doyle

unread,
Jan 4, 2022, 1:23:47 AM1/4/22
to skia-discuss
Do you need to redraw all the paths for every zoom level? Why not just draw to a picture and draw that for different zoom? You can also try to apply clip.
Reply all
Reply to author
Forward
0 new messages