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
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:5a64c1f5-94ba-250e-adc9-795abd6e2e97 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E4CC:B0660:4A90F5:68FE21:696A0C8D |
| html-safe-nonce | 55e49b7ba965ccc17d68796cdeeea559a693836ad07d22bc0cb8042e8094bf2c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNENDOkIwNjYwOjRBOTBGNTo2OEZFMjE6Njk2QTBDOEQiLCJ2aXNpdG9yX2lkIjoiODYxNjIwMDY2MzgzNTc0MTMyNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 07ad357b49eb0ef16b84172f0d3cad02a83d9e9e0fa35e987914a3c9acf0c112 |
| hovercard-subject-tag | pull_request:1165595588 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/100252/files |
| twitter:image | https://avatars.githubusercontent.com/u/61586?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/61586?s=400&v=4 |
| og:image:alt | 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 ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 699227a00bbb7fe1eec276d2ae1c3a93068bc5ba483bd9dc4b2a27a8f4f2f595 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7266b2d935baa1c6474b16dd9feaa5ca30607261 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width