{"action":"created","issue":{"url":"https://api.github.com/repos/python/cpython/issues/5273","repository_url":"https://api.github.com/repos/python/cpython","labels_url":"https://api.github.com/repos/python/cpython/issues/5273/labels{/name}","comments_url":"https://api.github.com/repos/python/cpython/issues/5273/comments","events_url":"https://api.github.com/repos/python/cpython/issues/5273/events","html_url":"https://github.com/python/cpython/pull/5273","id":290667563,"number":5273,"title":"bpo-31333: Re-implement ABCMeta in C","user":{"login":"ilevkivskyi","id":12005495,"avatar_url":"https://avatars1.githubusercontent.com/u/12005495?v=4","gravatar_id":"","url":"https://api.github.com/users/ilevkivskyi","html_url":"https://github.com/ilevkivskyi","followers_url":"https://api.github.com/users/ilevkivskyi/followers","following_url":"https://api.github.com/users/ilevkivskyi/following{/other_user}","gists_url":"https://api.github.com/users/ilevkivskyi/gists{/gist_id}","starred_url":"https://api.github.com/users/ilevkivskyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilevkivskyi/subscriptions","organizations_url":"https://api.github.com/users/ilevkivskyi/orgs","repos_url":"https://api.github.com/users/ilevkivskyi/repos","events_url":"https://api.github.com/users/ilevkivskyi/events{/privacy}","received_events_url":"https://api.github.com/users/ilevkivskyi/received_events","type":"User","site_admin":false},"labels":[{"id":536945472,"url":"https://api.github.com/repos/python/cpython/labels/CLA%20signed","name":"CLA signed","color":"0e8a16","default":false},{"id":666980059,"url":"https://api.github.com/repos/python/cpython/labels/awaiting%20merge","name":"awaiting merge","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":102,"created_at":"2018-01-23T00:36:14Z","updated_at":"2018-02-15T10:32:40Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/python/cpython/pulls/5273","html_url":"https://github.com/python/cpython/pull/5273","diff_url":"https://github.com/python/cpython/pull/5273.diff","patch_url":"https://github.com/python/cpython/pull/5273.patch"},"body":"This implementation is fully functional but there are three remaining issues/questions that I hope we can resolve quickly:\r\n* One test still fails. This is because `six.with_metaclass` (used by `pip`) does some fragile \"magic\". With this PR it fails with `TypeError: type.__new__(metaclass) is not safe, use ABCMeta.__new__()`. I see two options here: (1) Try to somehow special-case `ABCMeta` to fix this; (2) Do nothing here, but instead contact `six` and `pip` maintainers so that hey can fix this.\r\n* What to do with private caches/registry? There are three options: (1) Make them fully internal (i.e. only visible in C code); (2) Expose them, but make them read-only, so that one can do `C._abc_cache.clear()`, but _not_ `C._abc_cache = \"Surprise!\"`; (3) Expose them, and make them writable. I currently go with option (2), which seems to be a reasonable compromise.\r\n* How to organize the caches? In this version I made both caches and registry just normal sets of weak references without callbacks. This is very simple in terms of implementation and fast, with a minor downside that dead references will stay in caches. I am open to alternative ideas here (note the main issue is that references should not be removed during iteration over the sets).\r\n\r\nI didn't do any careful benchmarking yet, but this this seems to give a decent speed-up for Python start-up time and to several ABC-related tests. For example, on my machine Python startup is 10% faster.\r\n\r\n@methane @serhiy-storchaka I will really appreciate your help/advise/review here.\r\n\r\n@ned-deily I know beta1 is very close, but I would like this to get in. I already discussed with @gvanrossum and he is OK with this getting into beta1.\r\n\r\n\n\n<!-- issue-number: bpo-31333 -->\nhttps://bugs.python.org/issue31333\n<!-- /issue-number -->\n"},"comment":{"url":"https://api.github.com/repos/python/cpython/issues/comments/365886973","html_url":"https://github.com/python/cpython/pull/5273#issuecomment-365886973","issue_url":"https://api.github.com/repos/python/cpython/issues/5273","id":365886973,"user":{"login":"methane","id":199592,"avatar_url":"https://avatars2.githubusercontent.com/u/199592?v=4","gravatar_id":"","url":"https://api.github.com/users/methane","html_url":"https://github.com/methane","followers_url":"https://api.github.com/users/methane/followers","following_url":"https://api.github.com/users/methane/following{/other_user}","gists_url":"https://api.github.com/users/methane/gists{/gist_id}","starred_url":"https://api.github.com/users/methane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/methane/subscriptions","organizations_url":"https://api.github.com/users/methane/orgs","repos_url":"https://api.github.com/users/methane/repos","events_url":"https://api.github.com/users/methane/events{/privacy}","received_events_url":"https://api.github.com/users/methane/received_events","type":"User","site_admin":false},"created_at":"2018-02-15T10:32:40Z","updated_at":"2018-02-15T10:32:40Z","author_association":"MEMBER","body":"Creating single class without methods:\r\n\r\n```\r\n$ ./python -m perf timeit --compare-to `pwd`/../master/python --python-names master:c-abc -s 'from abc import ABC' -- 'class C(ABC): pass'\r\nmaster: ..................... 23.7 us +- 0.1 us\r\nc-abc: ..................... 15.4 us +- 0.1 us\r\n\r\nMean +- std dev: [master] 23.7 us +- 0.1 us -> [c-abc] 15.4 us +- 0.1 us: 1.54x faster (-35%)\r\n```\r\n\r\nCreating single class with 10 methods:\r\n\r\n```\r\n$ ./python -m perf timeit --compare-to `pwd`/../master/python --python-names master:c-abc -s 'from abc import ABC' -- '\r\n> class C(ABC):\r\n>     def meth(self): pass\r\n>     a=b=c=d=e=f=g=h=i = meth\r\n> '\r\nmaster: ..................... 26.5 us +- 0.2 us\r\nc-abc: ..................... 17.5 us +- 0.2 us\r\n\r\nMean +- std dev: [master] 26.5 us +- 0.2 us -> [c-abc] 17.5 us +- 0.2 us: 1.51x faster (-34%)\r\n```\r\n\r\nCreating 5 classes:\r\n\r\n```\r\n$ ./python -m perf timeit --compare-to `pwd`/../master/python --python-names master:c-abc -s 'from abc import ABC' -- 'class C(ABC): pass\r\nclass D(C): pass\r\nclass E(D): pass\r\nclass F(E): pass\r\nclass G(F): pass\r\n> '\r\nmaster: ..................... 143 us +- 2 us\r\nc-abc: ..................... 99.9 us +- 1.4 us\r\n\r\nMean +- std dev: [master] 143 us +- 2 us -> [c-abc] 99.9 us +- 1.4 us: 1.43x faster (-30%)\r\n```\r\n\r\nMaybe, we can say \"Creating ABC class is 1.5x faster.\""}}
{"actor":{"display_login":"methane"}}