Slow performance when drawing thick lines

471 views
Skip to first unread message

Maxim Rylov

unread,
Sep 7, 2016, 4:12:55 AM9/7/16
to skia-discuss

Hi,


I've tried to test Xamarin's C# wrapper for Skia called SkiaSharp. I guess that an issue that I've found in my tests might relate to Skia.


On Windows, SkiaSharp performs very slow in comparison to GDI+ when it comes to draw thick lines (stroke width greater than 1 pixel). To help you reproduce this issue, I've created a GitHub repository with a rather simple benchmark which compares the performance of SkiSharp and GDI+.

On my machine I got the following results:


Host Process Environment Information:
BenchmarkDotNet=v0.9.8.0
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i3 CPU M 380 2.53GHz, ProcessorCount=4
Frequency=2467784 ticks, Resolution=405.2219 ns, Timer=TSC
CLR=MS.NET 4.0.30319.42000, Arch=64-bit RELEASE [RyuJIT]
GC=Concurrent Workstation
JitModules=clrjit-v4.6.1532.0

Type=Benchmarks  Mode=Throughput  GarbageCollection=Concurrent Workstation  
Method AntiAlias Median StdDev
MethodAntiAliasMedianStdDev
Skia_ClearFalse626.0689 us33.5835 us
GDI_ClearFalse1,883.3675 us92.5697 us
Skia_DrawLines_SolidThickFalse34.3181 us2.3956 us
GDI_DrawLines_SolidThickFalse69.2968 us3.5125 us
Skia_DrawLines_SolidThinFalse33.6100 us2.0326 us
GDI_DrawLines_SolidThinFalse31.2110 us0.7240 us
Skia_DrawLines_DashedThickFalse216.3211 us7.8385 us
GDI_DrawLines_DashedThickFalse198.5229 us5.8046 us
Skia_DrawLines_DashedThinFalse216.9377 us9.8053 us
GDI_DrawLines_DashedThinFalse85.8987 us1.6362 us

Skia_Clear
True689.3211 us18.8872 us
GDI_ClearTrue1,882.9171 us54.4645 us
Skia_DrawLines_SolidThickTrue925.7412 us27.4917 us
GDI_DrawLines_SolidThickTrue331.8494 us16.4880 us
Skia_DrawLines_SolidThinTrue39.8524 us1.3069 us
GDI_DrawLines_SolidThinTrue297.3545 us3.2218 us
Skia_DrawLines_DashedThickTrue646.9674 us2.7239 us
GDI_DrawLines_DashedThickTrue341.4178 us1.2708 us
Skia_DrawLines_DashedThinTrue128.6211 us1.1245 us
GDI_DrawLines_DashedThinTrue503.6172 us1.7782 us


As it can be seen from the table (see the case when AntiAlias = True), Skia_DrawLines_SolidThick (stroke width equals 2 px) method is 2.78 times slower than its GDI+ counterpart GDI_DrawLines_SolidThick. Next, the performance of thick dashed strokes is a bit better, namely, Skia_DrawLines_DashedThick is 1.89 times slower than GDI_DrawLines_DashedThick.
At the same time, SkiaSharp is able to draw thin solid lines 7.46 times faster than GDI+. The difference in drawing thin dashed lines is 3.9 times respectively.


Do you have any explanation for such performance degradation of Skia when drawing thick lines?


Thank you in advance.





















































































Shawn Riordan

unread,
Sep 7, 2016, 6:04:32 AM9/7/16
to skia-discuss
It might help if your drawLines() calls included info about point count and other details.

E. Greg Daniel

unread,
Sep 7, 2016, 8:48:20 AM9/7/16
to skia-discuss
Do you know if your test uses Skia's CPU or GPU backend? Also, just for sanity check, are you running a release build for both Skia and GDI. I know skia has a lot of debug code that can be slow if run in that way.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Mike Klein

unread,
Sep 7, 2016, 8:58:37 AM9/7/16
to skia-discuss
From the code in the Github repo, it looks like it's drawing with software (I don't see the GPU backend exposed in SkiaSharp).  I imagine users of SkiaSharp do not build Skia themselves, so it's likely the equivalent of Release all across the board.

Maxim Rylov

unread,
Sep 9, 2016, 3:45:02 AM9/9/16
to skia-discuss
I ran the benchmark only with release builds, SkiaSharp has been configured to use the CPU backend.

The DrawLine method looks as follows

[Benchmark]
public void Skia_DrawLines_SolidThick()
{
    foreach (LineSegment ls in lineSegments)
      skCanvas.DrawLine(ls.X0, ls.Y0, ls.X1, ls.Y1, skPaintSolidThick);
}

where lineSegments is an array containing just one element LineSegment(-10F, -10F, 1200F, 1200F).

Matthew Leibowitz

unread,
Sep 9, 2016, 2:41:33 PM9/9/16
to skia-discuss
I think we are building a release version. 

I build with MSVC using these env vars:
GYP_GENERATORS="skia_arch_type='x86' skia_gpu=1"
GYP_DEFINES="ninja,msvs"

I then build with msbuild Release configuration. Does this do it, or is there some release bit that needs to go into the generators?
Reply all
Reply to author
Forward
0 new messages