ImageSharp.Drawing icon indicating copy to clipboard operation
ImageSharp.Drawing copied to clipboard

Cache ScanEdgeCollection in InternalPath

Open antonfirsov opened this issue 5 years ago • 3 comments

Creation of ScanEdgeCollection can take up to ~7% according to profiler results, so this seems to be a reasonable optimization. Instances shall be keyed by subsampling since y values in ScanEdge-s are rounded to subpixel scanlines.

Related: #103

antonfirsov avatar Nov 13 '20 17:11 antonfirsov

Do you have any pointers here. I don't really follow the issue.

JimBobSquarePants avatar May 05 '23 10:05 JimBobSquarePants

Most (all?) IPath implementations cache their tessellation data as an InternalPath member. Whenever we render an IPath (InternalPath) with a given subsampling, we first convert the InternalPath to a TessellatedMultipolygon (which is just a more efficient storage for the points in InternalPath), then create a ScanEdgeCollection which is a data structure that already depends on the value of subsampling.

Assuming it's a common use case to render an IPath multiple times (which might be a wrong assumption! ... we should analyze use-cases), we could create a cache of ScanEdgeCollections inside InternalPath, so we don't need to recreate it on each render run. Since ScanEdgeCollection depends on subsampling, we should cache (int, ScanEdgeCollection) pairs. In fact one pair should be enough, since we don't expect users to switch the subsampling ratio between render runs.

antonfirsov avatar May 05 '23 16:05 antonfirsov

Just had a read of the code there. You're on your own. Bit too complicated for me just now! 😆

JimBobSquarePants avatar May 06 '23 12:05 JimBobSquarePants