Skip to content

gh-100870: A per-class type cache #100869

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

Closed
wants to merge 6 commits into from

Conversation

Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Jan 9, 2023

See faster-cpython/ideas#532.

The main benefit is shrinking the inline cache for LOAD_ATTR.

One design flaw is that there is no way to reclaim space occupied by methods that no longer exist (e.g if a method is deleted). My assumption is that most normal code doesn't continuously delete methods though.

@Fidget-Spinner Fidget-Spinner changed the title A per-class type cache gh-100870: A per-class type cache Jan 9, 2023
@Fidget-Spinner
Copy link
Member Author

@markshannon could you please run this on the Faster CPython pyperformance machine?

@@ -64,7 +64,7 @@ typedef struct {
uint16_t counter;
uint16_t type_version[2];
uint16_t keys_version[2];
Copy link
Member Author

Choose a reason for hiding this comment

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

We can shrink this even further by reducing type_version and keys_version in the future.

@Fidget-Spinner
Copy link
Member Author

An alternative approach is to store the index into the global type cache instead. That will save us some space since we will no longer need to allocate a per-class cache. We can also make it effectively clean up dead methods id they're all in there.

@gvanrossum
Copy link
Member

One design flaw is that there is no way to reclaim space occupied by methods that no longer exist (e.g if a method is deleted). My assumption is that most normal code doesn't continuously delete methods though.

But what about systems that repeatedly reload a module? That doesn't strike me as totally abnormal.

@Fidget-Spinner
Copy link
Member Author

Fidget-Spinner commented Jan 10, 2023

I can overcome that with a little more space by attaching the type cache index to the method descriptor. Then during method cleanup I set that index to NULL.

@encukou
Copy link
Member

encukou commented Apr 10, 2024

@Fidget-Spinner, what's the status of this PR?

@Fidget-Spinner
Copy link
Member Author

@encukou I think we might need this for free-threaded eventually. But I'd rather open a new PR at that point. So time to close this,

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.

4 participants