Skip to content
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

Optimize shape rendering (pen creation mostly). #5997

Merged
merged 2 commits into from
Jun 3, 2021

Conversation

MarchingCube
Copy link
Collaborator

What does the pull request do?

An optimization for core Shape rendering that minimizes perf and memory impact.
Best case (no brushes) improved cpu perf x200 and removed all allocations.
Worst case we are looking at cpu perf x38 and 98% memory reduction.

What is the current behavior?

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
Render_Line_NoBrushes 9.246 us 0.0540 us 0.0506 us 0.7019 0.0153 - 3.01 KB
Render_Line_WithStroke 14.182 us 0.0617 us 0.0577 us 0.7782 0.0305 - 3.32 KB
Render_Line_WithFill 9.320 us 0.0447 us 0.0373 us 0.7019 0.0153 - 3.01 KB
Render_Line_WithFillAndStroke 13.953 us 0.0374 us 0.0312 us 0.7782 0.0305 - 3.32 KB

What is the updated/expected behavior with this PR?

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
Render_Line_NoBrushes 45.30 ns 0.092 ns 0.086 ns - - - -
Render_Line_WithStroke 339.26 ns 1.937 ns 1.812 ns 0.0210 - - 88 B
Render_Line_WithFill 87.35 ns 0.374 ns 0.332 ns - - - -
Render_Line_WithFillAndStroke 352.55 ns 2.207 ns 2.065 ns 0.0210 - - 88 B

How was the solution implemented (if it's not obvious)?

Best optimization is to just avoid doing any work, so when Stroke is not set we can just ignore it.
Also majority of rendered shapes are not using dashes so there is no point in allocating dash style for everything.

Biggest change is using immutable pen and dash styles. Mutable variants have an absurd overhead due to change tracking.

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

@MarchingCube MarchingCube requested a review from grokys May 29, 2021 23:07
@grokys grokys merged commit 8f83939 into AvaloniaUI:master Jun 3, 2021
danwalmsley pushed a commit that referenced this pull request Jun 4, 2021
Optimize shape rendering (pen creation mostly).
@MarchingCube MarchingCube deleted the shape-render-optimization branch June 4, 2021 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants