Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MNT: Remove cached renderer from figure #23202

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

Merged
merged 1 commit into from
Aug 12, 2022

Conversation

greglucas
Copy link
Contributor

PR Summary

Let the canvas decide whether to cache the renderer or not and let the figure request the renderer from the canvas. The canvas can either return a cached version or a new one.

This is a proof-of-concept after the discussion on the dev call last week to see if we can move the cache from the figure-level to the canvas-level.

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

lib/matplotlib/backends/backend_wx.py Show resolved Hide resolved
lib/matplotlib/tests/test_backend_macosx.py Outdated Show resolved Hide resolved
"""
if self.figure._cachedRenderer is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On one hand, this call making a new renderer would be odd, my understanding of why this exists is a helper specifcally for managing blitting where you can rely on the render not only existing, but also having already had everything else of interest rasterized. By caching the renderer on the figure we are saying "yes, this figure was rendered with this renderer so we are sure that it is holding the state of everything else, also you can use it to draw the given artist". If we cache / create the renderer on the canvas we only get "this renderer will work".

However, that is a narrow case and while I can think of stories of how this would break someone ("catch the AttirbuteError to know we need to re-render the whole figure"....but for that to make sense we would also have to be sure that we were properly invalidating the cache (by setting it to None) when we resize the Figure).

Which is a very long way of saying that I am 👍🏻 on this change (despite some risk), will need an API change note.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with all of that. I was a bit surprised that there wasn't more code churn in this PR which does make me a bit hesitant about what the edge-cases I'm missing are...

One thing I thought about is that we have a get_renderer() method on Agg/Cairo Canvas' now, but not on PDF, but the PDF requires a file handle so it isn't as straightforward to just point to a renderer. I was curious if that was perhaps the idea behind the figure caching in the first place... But, surprisingly it didn't affect any of the PDF tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pdf and svg renderer's work in a streaming mode so going back to one only makes limited sense in general and makes no sense in this case.

lib/matplotlib/axes/_base.py Outdated Show resolved Hide resolved
doc/api/axes_api.rst Outdated Show resolved Hide resolved
Let the canvas decide whether to cache the renderer or not and
request the renderer from the canvas. The canvas can either return
a cached version or a new one.
@tacaswell tacaswell added this to the v3.6.0 milestone Aug 12, 2022
@tacaswell tacaswell merged commit dc7b785 into matplotlib:main Aug 12, 2022
@greglucas greglucas deleted the cached-renderer branch August 12, 2022 14:22
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.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.