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

Cache a few things to speed up canvas rendering. #209

Merged
merged 1 commit into from Jan 18, 2022

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Jan 18, 2022

Caching a few values and a scratch surface can give us some nice wins, particularly for rendering a zoomed in canvas.

Original

Method Mean Error StdDev Allocated
RenderOneToOne 2.159 ms 0.0388 ms 0.0363 ms 242 B
RenderManyOneToOne 9.597 ms 0.1060 ms 0.0940 ms 824 B
RenderZoomIn 42.322 ms 0.2513 ms 0.2350 ms 29,294 B
RenderManyZoomIn 404.774 ms 3.2200 ms 3.0120 ms 29,600 B
RenderZoomOut 8.205 ms 0.1055 ms 0.0987 ms 272 B
RenderManyZoomOut 76.499 ms 0.7711 ms 0.7213 ms 1,574 B

PR

Method Mean Error StdDev Allocated
RenderOneToOne 2.144 ms 0.0155 ms 0.0145 ms 250 B
RenderManyOneToOne 9.529 ms 0.0866 ms 0.0810 ms 832 B
RenderZoomIn 22.584 ms 0.1647 ms 0.1460 ms 28,358 B
RenderManyZoomIn 123.765 ms 0.7484 ms 0.7001 ms 29,637 B
RenderZoomOut 8.179 ms 0.0824 ms 0.0771 ms 280 B
RenderManyZoomOut 65.336 ms 0.3871 ms 0.3432 ms 983 B

@cameronwhite
Copy link
Member

This is great, thanks!!

@cameronwhite cameronwhite merged commit 8ca0457 into PintaProject:master Jan 18, 2022
@cameronwhite
Copy link
Member

Thinking about this more, I wonder if the zoom in/out drawing could be done purely in Cairo by setting up a suitable transform for the source surface? The filtering behaviour would probably be different, but this could make it easy to draw straight onto the final surface with the layer's opacity / blend mode

@jpobst jpobst deleted the canvas-speedup branch January 18, 2022 05:28
@jpobst
Copy link
Contributor Author

jpobst commented Jan 18, 2022

I was wondering about that, especially for 'Zoom Out'.

I think 'Zoom In' is a bit trickier because most zoom functions apply a smoothing algorithm, and we want our 'Zoom In' to just show big, chunky pixels instead of being smoothed.

@cameronwhite
Copy link
Member

Looking through the Cairo docs, it looks like that might be doable by setting up the "fast" or "nearest" filter for the source surface pattern

@cameronwhite
Copy link
Member

I've got this mostly working, I'll upload a PR for it shortly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants