-
Notifications
You must be signed in to change notification settings - Fork 474
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
minor optimisations #1084
minor optimisations #1084
Conversation
@wieslawsoltes I closed the single PRs and placed all changes in this one. |
@AntonyCorbett Could you add benchmarks for those optimizations' https://github.com/svg-net/SVG/tree/master/Tests/Svg.Benchmark |
for (var i = graphicsPath.PointCount - 1; i >= 0; --i) | ||
if ((graphicsPath.PathTypes[i] & 0x7) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PathTypes allocates byte[] each time in this loop
@@ -17,7 +17,7 @@ public static string ToSvgString(this float value) | |||
|
|||
public static string ToSvgString(this PointF p) | |||
{ | |||
return p.X.ToSvgString() + " " + p.Y.ToSvgString(); | |||
return $"{p.X.ToSvgString()} {p.Y.ToSvgString()}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduces string allocation in SOH, improving perf
@@ -111,7 +111,7 @@ public object Clone() | |||
|
|||
public override string ToString() | |||
{ | |||
return string.Join(" ", this.Select(p => p.ToString()).ToArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary allocation to array
My simple test involves the use of a 30MB SVG file (so not sure that you would want me to include it). The benchmark code is as follows:
Results for non-optimised code: Results for optimised code: |
Looking great 👍 Btw what I meant for benchmark is to be more granular and cover just one optimization, you can see the existing benchmarks are done that way. It helps preventing regression and easier finding what those caused. |
@@ -39,19 +39,19 @@ public override Brush GetBrush(SvgVisualElement renderingElement, ISvgRenderer r | |||
chain.Add(curr); | |||
curr = SvgDeferredPaintServer.TryGet<SvgPatternServer>(curr.InheritGradient, renderingElement); | |||
} while (curr != null); | |||
|
|||
var firstChildren = chain.Where(p => p.Children.Count > 0).FirstOrDefault(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove spaces.
…erators Nuget README.md Samples Source Svg.Custom Tests doc docfx.json index.md license.txt minor optimisations BuildProcessTemplates CONTRIBUTING.md Generators Nuget README.md Samples Source Svg.Custom Tests doc docfx.json index.md license.txt avoid materialisation of enumerable.
….md Generators Nuget README.md Samples Source Svg.Custom Tests doc docfx.json index.md license.txt minor optimisations BuildProcessTemplates CONTRIBUTING.md Generators Nuget README.md Samples Source Svg.Custom Tests doc docfx.json index.md license.txt avoid materialisation of enumerable.
Set of small optimisations to reduce SOH allocations on hot paths. Provides ~20% reduction in time to process very large SVG data.