Skip to content

[WIP] bpo-36560: _abc now uses weakref.WeakSet type #12743

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 1 commit into from
Closed

[WIP] bpo-36560: _abc now uses weakref.WeakSet type #12743

wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Apr 9, 2019

The C accelerator _abc now uses the weakref.WeakSet type rather than
the set type holding weak references.

Changes:

  • _abc._get_dump() now returns lists rather than sets.
  • subclasscheck_check_registry() now longer holds a second strong
    reference to 'rkey' to call PyObject_IsSubclass(): the 'registry'
    list already holds a strong reference.

https://bugs.python.org/issue36560

@vstinner
Copy link
Member Author

vstinner commented Apr 9, 2019

@ilevkivskyi: I wrote this PR to try to debug https://bugs.python.org/issue36560

That's also why I had to fix regrtest when _abc is not built: https://bugs.python.org/issue36565

Honestly, I'm not sure that using weakref.WeakSet type provides any benefit compared to the current implementation, but I wanted to show you the code just in case :-)

I'm also using this PR to debug https://bugs.python.org/issue36560 even if modifying Modules/Setup to disable the compilation of the _abc module should have the same effect: Lib/_py_abc.py already uses weakref.WeakSet, so it should provide the same behavior than this PR.

The C accelerator _abc now uses the weakref.WeakSet type rather than
the set type holding weak references.

Changes:

* _abc._get_dump() now returns lists rather than sets.
* subclasscheck_check_registry() now longer holds a second strong
  reference to 'rkey' to call PyObject_IsSubclass(): the 'registry'
  list already holds a strong reference.
@vstinner
Copy link
Member Author

vstinner commented Apr 9, 2019

Honestly, I'm not sure that using weakref.WeakSet type provides any benefit compared to the current implementation, but I wanted to show you the code just in case :-)

Moreover, I didn't measure the performance impact yet. Lib/_weakset.py is implemented fully in pure-Python: it might be slower than your efficient implementation written in C.

@ilevkivskyi
Copy link
Member

Yes, WeakSet was considered initially when we worked on this. IIRC we decided to not do this because it was slow. Also TBH it doesn't add much in readability. Anyway, thanks for debugging the refleaks!

@vstinner
Copy link
Member Author

vstinner commented Apr 9, 2019

Please keep this PR open until https://bugs.python.org/issue36560 is closed.

@vstinner vstinner closed this Apr 26, 2019
@vstinner vstinner deleted the _abc_weakref branch April 26, 2019 09:10
@vstinner
Copy link
Member Author

This PR isn't really needed to debug https://bugs.python.org/issue36560 : modify Modules/Setup to no longer compile "_abc" does basically the same thing than this PR.

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