Repository navigation
The performance of 'DrawLines' degrades the thinner the lines are #18
Description
Activity
- changed the title
[-]The performance of DrawLine degrades the thinner the lines are[/-][+]The performance of `DrawLines` degrades the thinner the lines are[/+]on Jun 15, 2019 - changed the title
[-]The performance of `DrawLines` degrades the thinner the lines are[/-][+]The performance of 'DrawLines' degrades the thinner the lines are[/+]on Jun 15, 2019 Thanks @pmcxs for all the detail.
We're planning on separating ImagSharp.Drawing into a separate repository as we really haven't begun to do the same performance work on that library as we have the main library and we don't want to delay the main libraries RC1 release .
It would be brilliant if you have any advice to give once we do that migration.
Wouldn't a simple explanation behind why larger lines are faster is because the stopwatch includes the PNG saving to disk and larger lines produce a less-complex PNG and therefore improves performance during serialization.
Reacted by James Jackson-South@implemental Yep, that’s definitely a factor. I hadn’t actually looked at the benchmarking code.... it’s not great.
System.Drawing saves png’s at zlib compression level 1 with no filter where we use level 6 with paeth filtering. The encoding speed alone with be 2-3x slower.
There are two factors explaining this:
- The thinner the lines, the more points will the final tessellated polygon contain (after extending the multiline with the polygon thickness). In my experiment I've seen ~200x more points in the tessellation with the provided repro code with thickness 1px vs 10px EDIT: 200x degenerate, see The performance of 'DrawLines' degrades the thinner the lines are #18 (comment)
- The performance of the scanning code on current master is very bad, and degrades with the number of (tessellated polygon) points in a non-linear manner.
I don't think we can do anything with (1) since it's just the math behind extending a multi-line to a polygon. (2) will be fixed with #96.
@pmcxs if still interested, check out our nightly builds after we merge that PR (ETA: couple of days).
Actually,
(numberOfLines=1000, lineWidth=10)is a degenerate case, where the500x500canvas will be filled with mess so I it's not a useful baseline. In normal cases the multiplier between 1px and 10px is much smaller.I consider this issue to be fixed by #96.
Prerequisites
DEBUGandRELEASEmodeDescription
Drawing thinner lines takes much more time to process than broader lines.
The following tests were done on a 500x500 image (sorted by processing time):
1000 10px lines render faster than 100 1px lines, which seems strange.
Steps to Reproduce
Option 1
Create a simple project, referencing the latest ImageSharp library and include the code below:
Option 2
This was detected on a comparison between ImageSharp, System.Drawing and a custom simplified implementation. That benchmark is available at: https://github.com/pmcxs/core-linedrawing-benchmark/. It can be executed to replicate the issue:
System Configuration