Title: Reduce redundant object creation while calling callback function from gc · Issue #104028 · python/cpython · GitHub
Open Graph Title: Reduce redundant object creation while calling callback function from gc · Issue #104028 · python/cpython
X Title: Reduce redundant object creation while calling callback function from gc · Issue #104028 · python/cpython
Description: cpython/Modules/gcmodule.c Lines 1391 to 1402 in 4b27972 for (Py_ssize_t i=0; i
Open Graph Description: cpython/Modules/gcmodule.c Lines 1391 to 1402 in 4b27972 for (Py_ssize_t i=0; i
X Description: cpython/Modules/gcmodule.c Lines 1391 to 1402 in 4b27972 for (Py_ssize_t i=0; i<PyList_GET_SIZE(gcstate->callbacks); i++) { PyObject *r, *cb = PyList_GET_ITEM(gcstate->callbacks, i); Py_IN...
Opengraph URL: https://github.com/python/cpython/issues/104028
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Reduce redundant object creation while calling callback function from gc","articleBody":"https://github.com/python/cpython/blob/4b27972f5fe816d3616f97f8643d8ad922473ab5/Modules/gcmodule.c#L1391-L1402\r\n\r\nThe phase object can be created earlier with one-time creation and it can be replaced with vectorcall either.\r\nFrom my microbenchmark, there is 4-5% performance improvement by doing this.\r\n\r\n## microbenchmark\r\n```python\r\n\r\nimport pyperf\r\nimport gc\r\n\r\n\r\ndef benchamark_collection(loops):\r\n def callback_foo(phase, info):\r\n pass\r\n for _ in range(100):\r\n gc.callbacks.append(callback_foo)\r\n\r\n total_time = 0\r\n for _ in range(loops):\r\n t0 = pyperf.perf_counter()\r\n collected = gc.collect()\r\n total_time += pyperf.perf_counter() - t0\r\n return total_time\r\n\r\n\r\nif __name__ == \"__main__\":\r\n runner = pyperf.Runner()\r\n runner.metadata[\"description\"] = \"GC callback benchmark\"\r\n runner.bench_time_func(\"create_gc_cycles\", benchamark_collection)\r\n`````\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-104030\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/corona10","@type":"Person","name":"corona10"},"datePublished":"2023-05-01T05:08:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/104028/cpython/issues/104028"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5c4e9042-8044-4cbf-f9f1-87059fa0c917 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9CC4:28B0D7:4049CF:5B7CA2:696A0AFA |
| html-safe-nonce | 502c9d764be01222ecc81f3e504eeb084b71cb9bd70ffc1e09c8e41702b0b441 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Q0M0OjI4QjBENzo0MDQ5Q0Y6NUI3Q0EyOjY5NkEwQUZBIiwidmlzaXRvcl9pZCI6IjUyODc0OTU5Njc0MjA1ODI2NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a402b0b7f4c65069a07d8b8c9e48babc7477f35539a6011f40caca82a85d99f7 |
| hovercard-subject-tag | issue:1690384429 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/104028/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c885777a256e79c506e140ebe9b373f831c0e7dd834053ec43c600fe34a5868e/python/cpython/issues/104028 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c885777a256e79c506e140ebe9b373f831c0e7dd834053ec43c600fe34a5868e/python/cpython/issues/104028 |
| og:image:alt | cpython/Modules/gcmodule.c Lines 1391 to 1402 in 4b27972 for (Py_ssize_t i=0; i |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | corona10 |
| 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 |
| 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