Skip to content

Use collections.deque to store animation cache data. #30206

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
Jun 24, 2025

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 22, 2025

deques are exactly suited for the task at hand, and should be (here, marginally) more efficient than repeatedly slicing off the start of the list.

Also drop unneeded reference to old_frame_seq (the iterator already keeps that data alive).

PR summary

PR checklist

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

There is a self._save_seq = [] in _init_draw that was missed.


super().__init__(fig, **kwargs)

# Need to reset the saved seq, since right now it will contain data
# for a single frame from init, which is not what we want.
self._save_seq = []
self._save_seq = collections.deque([], self._save_count)
Copy link
Member

Choose a reason for hiding this comment

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

Can't just clear it?

Suggested change
self._save_seq = collections.deque([], self._save_count)
self._save_seq.clear()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, even better.

deques are exactly suited for the task at hand, and should be (here,
marginally) more efficient than repeatedly slicing off the start of the
list.

Also drop unneeded reference to old_frame_seq (the iterator already
keeps that data alive).
@anntzer
Copy link
Contributor Author

anntzer commented Jun 23, 2025

thanks, fixed

@jkseppan jkseppan added this to the v3.11.0 milestone Jun 24, 2025
@jkseppan jkseppan merged commit 0dcd06f into matplotlib:main Jun 24, 2025
40 checks passed
@anntzer anntzer deleted the ad branch June 24, 2025 15:55
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