René's URL Explorer Experiment


Title: gh-92810: Reduce memory usage by ABCMeta.__subclasscheck__ (alternative2) by dolfinus · Pull Request #150540 · python/cpython · GitHub

Open Graph Title: gh-92810: Reduce memory usage by ABCMeta.__subclasscheck__ (alternative2) by dolfinus · Pull Request #150540 · python/cpython

X Title: gh-92810: Reduce memory usage by ABCMeta.__subclasscheck__ (alternative2) by dolfinus · Pull Request #150540 · python/cpython

Description: Issue: gh-92810 Alternative implementation of #131914 which does not check __subclasses__ recursively. To handle cases like: class Number(ABC): ... class Real(Number): ... class Integral(Real): ... Integral.register(int) assert issubclass(int, Number) is True which previously were implemented via recursive __subclasses__ check, method cls.register(subclass) is calling super(cls).register(subclass) recursively ("bubble-up" registration to all the parents). For benchmark from #131914: sudo ./python -m pyperf system tune taskset -c 0 ./python benchmark.py --metaclass abc.ABCMeta --rounds 3 --classes 5000 taskset -c 0 ./python benchmark.py --metaclass _py_abc.ABCMeta --rounds 3 --classes 5000 Impl Max memory before, MB Max memory after, MB _abc 6331 50 _py_abc 4422 61 Impl Total time before Total time after _abc 6m 16s 1m 23s _py_abc 8m 48s 3m 53s Check Impl before after Impl before after isinstance(child, Parent) _abc 0.115us 4MiB...15MiB 0.121us 2MiB...15MiB _py_abc 0.212us 11MiB...24MiB 0.218us 11MiB...24MiB issubclass(Child, Parent) _abc 0.105us 0MiB...1MiB 0.111us 0MiB...1MiB _py_abc 0.203us 6MiB...8MiB 0.208us 5MiB...8MiB isinstance(child, Grandparent) _abc 0.112us 0MiB...2MiB 0.119us 1MiB...1MiB _py_abc 0.210us 4MiB...7MiB 0.216us 4MiB...7MiB issubclass(Child, Grandparent) _abc 0.103us 0MiB 0.108us 0MiB _py_abc 0.201us 0MiB...1MiB 0.207us 0MiB...1MiB not isinstance(child, Sibling) _abc 0.113us 4MiB...14MiB 0.121us 3MiB...14MiB _py_abc 0.348us 13MiB...23MiB 0.354us 13MiB...22MiB not issubclass(Child, Sibling) _abc 0.105us 1MiB 0.110us 1MiB...2MiB _py_abc 0.328us 8MiB...10MiB 0.332us 9MiB...11MiB not isinstance(child, Cousin) _abc 0.115us 1MiB...2MiB 0.121us 1MiB...2MiB _py_abc 0.350us 7MiB...9MiB 0.354us 7MiB...10MiB not issubclass(Child, Cousin) _abc 0.104us 0MiB 0.110us 0MiB...1MiB _py_abc 0.329us 4MiB 0.333us 4MiB...5MiB not isinstance(child, Uncle) _abc 7.268us 6174MiB...6333MiB 0.125us 0MiB...1MiB _py_abc 9.957us 4382MiB...4422MiB 0.360us 6MiB not issubclass(Child, Uncle) _abc 7.099us 6171MiB 0.114us 0MiB _py_abc 9.936us 4380MiB 0.336us 4MiB...5MiB Memory increment is measured during isinstance() / issubclass() calls, not during preparation, like class creation or registration where actual registry allocation is performed. So memory usage in tables below is almost always 0. Timing drop in _py_abc implementation for 2 first rows is due to if subclass in cls._abc_registry: check added to match _abc.c implementation. Check Impl before after Impl before after isinstance(child, Parent.register) _abc 0.273us 0MiB 0.272us 0MiB _py_abc 0.440us 0MiB 0.275us 0MiB issubclass(Child, Parent.register) _abc 0.154us 0MiB 0.157us 0MiB _py_abc 0.427us 0MiB 0.261us 0MiB isinstance(child, Grandparent.register) _abc 0.114us 0MiB 0.120us 0MiB _py_abc 0.253us 0MiB 0.262us 0MiB issubclass(Child, Grandparent.register) _abc 0.103us 0MiB 0.109us 0MiB _py_abc 0.240us 0MiB 0.247us 0MiB not isinstance(child, Sibling.register) _abc 0.027us 0MiB 0.030us 1MiB _py_abc 0.028us 0MiB 0.029us 2MiB not issubclass(Child, Sibling.register) _abc 0.018us 0MiB 0.018us 1MiB _py_abc 0.018us 0MiB 0.018us 2MiB not isinstance(child, Cousin.register) _abc 0.028us 0MiB 0.028us 2MiB _py_abc 0.028us 0MiB 0.029us 3MiB not issubclass(Child, Cousin.register) _abc 0.018us 0MiB 0.018us 2MiB _py_abc 0.019us 0MiB 0.018us 3MiB not isinstance(child, Uncle.register) _abc 0.249us 0MiB 0.233us 2MiB _py_abc 0.843us 0MiB 0.866us 3MiB not issubclass(Child, Uncle.register) _abc 0.238us 0MiB 0.227us 2MiB _py_abc 0.815us 0MiB 0.839us 3MiB Just to check that nothing is broken: Check Impl before after Impl before after not isinstance(child, Unrelated) _abc 0.028us 0MiB 0.028us 0MiB _py_abc 0.028us 0MiB 0.029us 0MiB not issubclass(Child, Unrelated) _abc 0.018us 0MiB 0.018us 0MiB _py_abc 0.018us 0MiB 0.018us 0MiB not isinstance(child, UnrelatedABC) _abc 0.118us 0MiB 0.121us 0MiB _py_abc 0.469us 0MiB 0.466us 0MiB not issubclass(Child, UnrelatedABC) _abc 0.110us 0MiB 0.112us 0MiB _py_abc 0.442us 0MiB 0.442us 0MiB Flamegraphs for _py_abc impl and test issubclass_uncle (the most time and memory consuming case on main): main_vs_pr150540.tar.gz

Open Graph Description: Issue: gh-92810 Alternative implementation of #131914 which does not check __subclasses__ recursively. To handle cases like: class Number(ABC): ... class Real(Number): ... class Integral(Real):...

X Description: Issue: gh-92810 Alternative implementation of #131914 which does not check __subclasses__ recursively. To handle cases like: class Number(ABC): ... class Real(Number): ... class Integral(Real):...

Opengraph URL: https://github.com/python/cpython/pull/150540

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:fee1a80a-6c59-ab11-1770-77f5579ed2da
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB2B2:2DBB21:32BF58F:43BCA32:6B01F827
html-safe-nonce122974609f072aa1c5ccac869787d36405fbcd9f48f6ced6c3a445a760ef072f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkIyOjJEQkIyMTozMkJGNThGOjQzQkNBMzI6NkIwMUY4MjciLCJ2aXNpdG9yX2lkIjoiMjE2MTM0MzU2ODM2Njc3NjcxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmace795800ea65ceeeb643d7b228ffe4c2baaf46b697aa71bdf2f19602f949babb1
hovercard-subject-tagpull_request:3758436405
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/150540/files
twitter:imagehttps://avatars.githubusercontent.com/u/4661021?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4661021?s=400&v=4
og:image:altIssue: gh-92810 Alternative implementation of #131914 which does not check __subclasses__ recursively. To handle cases like: class Number(ABC): ... class Real(Number): ... class Integral(Real):...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/150540/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F150540%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F150540%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/150540/files
Reloadhttps://github.com/python/cpython/pull/150540/files
Reloadhttps://github.com/python/cpython/pull/150540/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
dolfinushttps://github.com/dolfinus
python:mainhttps://github.com/python/cpython/tree/main
dolfinus:improvement/ABCMeta_subclasscheck_v3https://github.com/dolfinus/cpython/tree/improvement/ABCMeta_subclasscheck_v3
Conversation 3 https://github.com/python/cpython/pull/150540
Commits 4 https://github.com/python/cpython/pull/150540/commits
Checks 51 https://github.com/python/cpython/pull/150540/checks
Files changed https://github.com/python/cpython/pull/150540/files
Please reload this pagehttps://github.com/python/cpython/pull/150540/files
gh-92810: Reduce memory usage by ABCMeta.__subclasscheck__ (alternative2) https://github.com/python/cpython/pull/150540/files#top
Show all changes 4 commits https://github.com/python/cpython/pull/150540/files
38162ca gh-92810: Reduce memory usage by ABCMeta.__subclasscheck__ dolfinus May 27, 2026 https://github.com/python/cpython/pull/150540/commits/38162ca691da15a3365bf6466e02bab1077db3d5
091e2b7 📜🤖 Added by blurb_it. blurb-it[bot] May 27, 2026 https://github.com/python/cpython/pull/150540/commits/091e2b77f267c39ded285b3467516e81f127121e
dc63fcc gh-92810: Fix blurb message dolfinus May 27, 2026 https://github.com/python/cpython/pull/150540/commits/dc63fcc847cc3eab253ce9b2c69b268c7957380a
49e8b49 gh-92810: Fix compiler warning dolfinus May 27, 2026 https://github.com/python/cpython/pull/150540/commits/49e8b4931e351b36929500f6bd2573a980e8697e
Clear filters https://github.com/python/cpython/pull/150540/files
Please reload this pagehttps://github.com/python/cpython/pull/150540/files
Please reload this pagehttps://github.com/python/cpython/pull/150540/files
3.16.rst https://github.com/python/cpython/pull/150540/files#diff-e69e0be717f3409832d520e20348f62af39c9436ba1a9d82e842bc10e5eb51d7
_py_abc.py https://github.com/python/cpython/pull/150540/files#diff-3178d3e96fe6ef5531e7c1510815852772107bf2a222f4d94a1b3b85e4c13b0f
test_abc.py https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
test_isinstance.py https://github.com/python/cpython/pull/150540/files#diff-221b84ceb8809408af7e1851deabdf6ccd4e309b15e1cc4fc429ff4692d56d59
2026-05-27-22-49-42.gh-issue-92810._rILC7.rst https://github.com/python/cpython/pull/150540/files#diff-f9d367f6df6e92204b3138bc3e647a63fd7b84a7eb4289c1c616d3ceba22fe1e
_abc.c https://github.com/python/cpython/pull/150540/files#diff-d88c94f372c2e10cea3d5f2e39c6ce940eb2cfe664d913eeab7f74d23d636687
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L116
Doc/whatsnew/3.16.rsthttps://github.com/python/cpython/pull/150540/files#diff-e69e0be717f3409832d520e20348f62af39c9436ba1a9d82e842bc10e5eb51d7
View file https://github.com/python/cpython/blob/49e8b4931e351b36929500f6bd2573a980e8697e/Doc/whatsnew/3.16.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/150540/{{ revealButtonHref }}
https://github.com/python/cpython/pull/150540/files#diff-e69e0be717f3409832d520e20348f62af39c9436ba1a9d82e842bc10e5eb51d7
https://github.com/python/cpython/pull/150540/files#diff-e69e0be717f3409832d520e20348f62af39c9436ba1a9d82e842bc10e5eb51d7
Lib/_py_abc.pyhttps://github.com/python/cpython/pull/150540/files#diff-3178d3e96fe6ef5531e7c1510815852772107bf2a222f4d94a1b3b85e4c13b0f
View file https://github.com/python/cpython/blob/49e8b4931e351b36929500f6bd2573a980e8697e/Lib/_py_abc.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/150540/{{ revealButtonHref }}
https://github.com/python/cpython/pull/150540/files#diff-3178d3e96fe6ef5531e7c1510815852772107bf2a222f4d94a1b3b85e4c13b0f
https://github.com/python/cpython/pull/150540/files#diff-3178d3e96fe6ef5531e7c1510815852772107bf2a222f4d94a1b3b85e4c13b0f
https://github.com/python/cpython/pull/150540/files#diff-3178d3e96fe6ef5531e7c1510815852772107bf2a222f4d94a1b3b85e4c13b0f
Lib/test/test_abc.pyhttps://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
View file https://github.com/python/cpython/blob/49e8b4931e351b36929500f6bd2573a980e8697e/Lib/test/test_abc.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/150540/{{ revealButtonHref }}
https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
https://github.com/python/cpython/pull/150540/files#diff-e020d5ddd536ec48b0414753af7d5240750a05262f32dad378b4c79e6cc3743d
Please reload this pagehttps://github.com/python/cpython/pull/150540/files
Please reload this pagehttps://github.com/python/cpython/pull/150540/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.