René's URL Explorer Experiment


Title: gh-83076: 3.8x speed improvement in (Async)Mock instantiation by carljm · Pull Request #100252 · python/cpython · GitHub

Open Graph Title: gh-83076: 3.8x speed improvement in (Async)Mock instantiation by carljm · Pull Request #100252 · python/cpython

X Title: gh-83076: 3.8x speed improvement in (Async)Mock instantiation by carljm · Pull Request #100252 · python/cpython

Description: This PR makes several performance optimizations to instantiation of Mock() and AsyncMock(). The changes are discussed in more detail in the linked issue #83076. The changes result in a net speedup of 3.8x for creation of both kinds of mocks. Before this PR: ➜ ./python -m timeit --setup="from unittest.mock import Mock" "Mock()" 2000 loops, best of 5: 97.9 usec per loop ➜ ./python -m timeit --setup="from unittest.mock import AsyncMock" "AsyncMock()" 500 loops, best of 5: 678 usec per loop After this PR: ➜ ./python -m timeit --setup="from unittest.mock import Mock" "Mock()" 10000 loops, best of 5: 25.6 usec per loop ➜ ./python -m timeit --setup="from unittest.mock import AsyncMock" "AsyncMock()" 2000 loops, best of 5: 181 usec per loop There's also one simple code cleanup here: the AsyncMagicMixin.__init__ method was an exact duplicate of the inherited MagicMixin.__init__. This is unnecessary duplication, we can just inherit it instead. Issue: gh-83076

Open Graph Description: This PR makes several performance optimizations to instantiation of Mock() and AsyncMock(). The changes are discussed in more detail in the linked issue #83076. The changes result in a net speedup ...

X Description: This PR makes several performance optimizations to instantiation of Mock() and AsyncMock(). The changes are discussed in more detail in the linked issue #83076. The changes result in a net speedup ...

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

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:5a64c1f5-94ba-250e-adc9-795abd6e2e97
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE4CC:B0660:4A90F5:68FE21:696A0C8D
html-safe-nonce55e49b7ba965ccc17d68796cdeeea559a693836ad07d22bc0cb8042e8094bf2c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNENDOkIwNjYwOjRBOTBGNTo2OEZFMjE6Njk2QTBDOEQiLCJ2aXNpdG9yX2lkIjoiODYxNjIwMDY2MzgzNTc0MTMyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac07ad357b49eb0ef16b84172f0d3cad02a83d9e9e0fa35e987914a3c9acf0c112
hovercard-subject-tagpull_request:1165595588
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/100252/files
twitter:imagehttps://avatars.githubusercontent.com/u/61586?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/61586?s=400&v=4
og:image:altThis PR makes several performance optimizations to instantiation of Mock() and AsyncMock(). The changes are discussed in more detail in the linked issue #83076. The changes result in a net speedup ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None699227a00bbb7fe1eec276d2ae1c3a93068bc5ba483bd9dc4b2a27a8f4f2f595
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
release7266b2d935baa1c6474b16dd9feaa5ca30607261
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/100252/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F100252%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F100252%2Ffiles
Sign up https://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/100252/files
Reloadhttps://github.com/python/cpython/pull/100252/files
Reloadhttps://github.com/python/cpython/pull/100252/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/100252/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/pull/100252/files
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
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
cjw296https://github.com/cjw296
python:mainhttps://github.com/python/cpython/tree/main
carljm:fastmockhttps://github.com/carljm/cpython/tree/fastmock
Conversation 18 https://github.com/python/cpython/pull/100252
Commits 9 https://github.com/python/cpython/pull/100252/commits
Checks 0 https://github.com/python/cpython/pull/100252/checks
Files changed https://github.com/python/cpython/pull/100252/files
Please reload this pagehttps://github.com/python/cpython/pull/100252/files
gh-83076: 3.8x speed improvement in (Async)Mock instantiation https://github.com/python/cpython/pull/100252/files#top
Show all changes 9 commits https://github.com/python/cpython/pull/100252/files
8a2a39f gh-83076: ~4x speed improvement in (Async)Mock instantiation carljm Dec 14, 2022 https://github.com/python/cpython/pull/100252/commits/8a2a39f253e4ba3c2bb3d2172b71570cc4edb0c5
7a30565 📜🤖 Added by blurb_it. blurb-it[bot] Dec 14, 2022 https://github.com/python/cpython/pull/100252/commits/7a30565c2d70f45f7032a27ff7eb8b4641798d3a
597209d Remove redundant AsyncMagicMixin.__init__ method carljm Dec 14, 2022 https://github.com/python/cpython/pull/100252/commits/597209dd488d846acee5432bec6a8d1f4654566f
246772c Fix rst syntax in news blurb carljm Dec 14, 2022 https://github.com/python/cpython/pull/100252/commits/246772c2c4c6039c754eb1b452b17a1b3fc88e45
2260a54 Merge branch 'main' into fastmock carljm Dec 16, 2022 https://github.com/python/cpython/pull/100252/commits/2260a54c60538d55d410c72ae7bb5dfb321b8ef7
a03f843 fix instance-only async attr carljm Dec 16, 2022 https://github.com/python/cpython/pull/100252/commits/a03f84360e4830ffa63883ba52f6b5958c6bd16a
1b6241a Merge branch 'main' into fastmock carljm Dec 16, 2022 https://github.com/python/cpython/pull/100252/commits/1b6241abeb220fa38ca5301f48af060b2e91d2de
6595272 determine spec shape only at mock construction time carljm Dec 16, 2022 https://github.com/python/cpython/pull/100252/commits/6595272b2e5c64310c1eb4e7d1edba0689555c55
a9af20a Merge branch 'main' into fastmock carljm Dec 19, 2022 https://github.com/python/cpython/pull/100252/commits/a9af20a28427e659c3591f03800f8a84619e84ac
Clear filters https://github.com/python/cpython/pull/100252/files
Please reload this pagehttps://github.com/python/cpython/pull/100252/files
Please reload this pagehttps://github.com/python/cpython/pull/100252/files
testasync.py https://github.com/python/cpython/pull/100252/files#diff-701e692796f7bc8001aec6f354f4770ad9fdf05116ca6934fc1dbf7705f80fdb
mock.py https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
2022-12-14-17-37-01.gh-issue-83076.NaYzWT.rst https://github.com/python/cpython/pull/100252/files#diff-7d054d60160f28298df10f6a5d1c1306e7d465a45b968841810e2fa38b3d5989
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L611
Lib/test/test_unittest/testmock/testasync.pyhttps://github.com/python/cpython/pull/100252/files#diff-701e692796f7bc8001aec6f354f4770ad9fdf05116ca6934fc1dbf7705f80fdb
View file https://github.com/carljm/cpython/blob/a9af20a28427e659c3591f03800f8a84619e84ac/Lib/test/test_unittest/testmock/testasync.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/100252/{{ revealButtonHref }}
https://github.com/python/cpython/pull/100252/files#diff-701e692796f7bc8001aec6f354f4770ad9fdf05116ca6934fc1dbf7705f80fdb
https://github.com/python/cpython/pull/100252/files#diff-701e692796f7bc8001aec6f354f4770ad9fdf05116ca6934fc1dbf7705f80fdb
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L610
Lib/unittest/mock.pyhttps://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
View file https://github.com/carljm/cpython/blob/a9af20a28427e659c3591f03800f8a84619e84ac/Lib/unittest/mock.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/100252/{{ revealButtonHref }}
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
Please reload this pagehttps://github.com/python/cpython/pull/100252/files
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
Please reload this pagehttps://github.com/python/cpython/pull/100252/files
https://github.com/python/cpython/pull/100252/files#diff-347d0254250a1ab7ab8e31b405e2c35b74cd2838df4ee74f1b658a459eb91f1a
Misc/NEWS.d/next/Library/2022-12-14-17-37-01.gh-issue-83076.NaYzWT.rsthttps://github.com/python/cpython/pull/100252/files#diff-7d054d60160f28298df10f6a5d1c1306e7d465a45b968841810e2fa38b3d5989
View file https://github.com/carljm/cpython/blob/a9af20a28427e659c3591f03800f8a84619e84ac/Misc/NEWS.d/next/Library/2022-12-14-17-37-01.gh-issue-83076.NaYzWT.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/100252/{{ revealButtonHref }}
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.