Skip to content

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Sep 1, 2025

This type is immutable but it is a true container type, so it needs the GC. However I need to measure performances.

@picnixz

This comment was marked as resolved.

@picnixz
Copy link
Member Author

picnixz commented Sep 1, 2025

Oh there is a previous discussion: #76603. I'll check this.

@picnixz picnixz force-pushed the fix/gc/functools-heap-types-116946 branch from f4151b8 to 9b04072 Compare September 1, 2025 11:20
@picnixz
Copy link
Member Author

picnixz commented Sep 1, 2025

Mmh, so this now boils down to whether we want to make sure that the GC protocol is correctly implemented or if we want to keep performances.

@rhettinger
Copy link
Contributor

rhettinger commented Sep 1, 2025

The lru_cache_type_spec already is marked with Py_TPFLAGS_HAVE_GC and Py_TPFLAGS_IMMUTABLETYPE. And the lru_cache_tp_traverse is already visiting all of the _lru_list_elem entries. ISTM that all parts that can hold an object are already visible to GC and would be collected at shutdown. This PR seems unnecessary and will just hurt performance for no real use benefit.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Concur with @rhettinger.

Note also that the cache dict is already visited, and it visits all its elements, so they will be visited twice with this PR.

Also, clearing the key in lru_list_elem_clear() can have bad consequences.

@picnixz
Copy link
Member Author

picnixz commented Sep 1, 2025

I see. Ok I'll close this one and will just change the immutability bit when necessary in the other PRs.

@picnixz picnixz closed this Sep 1, 2025
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