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/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:2912e242-d44e-9d4f-2da6-9b85fa19b720 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | 8DC2:AA16D:197275:239B13:696A0F57 |
| html-safe-nonce | b87401b614328c84231ee7751e1c5fca5ae3b19feaa5b7874ccd9af8934f316d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4REMyOkFBMTZEOjE5NzI3NToyMzlCMTM6Njk2QTBGNTciLCJ2aXNpdG9yX2lkIjoiODQ4Mzg2MDQ0MjEzNDQ4Mjc3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 65f7b9a105fbe5c8f5fe26ac40410cc7585bbd2cd6eb74572759b25698c7b91c |
| hovercard-subject-tag | pull_request:1165595588 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,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/checks |
| 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 |
| 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 full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7266b2d935baa1c6474b16dd9feaa5ca30607261 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width