Title: gh-158592: Reallocate the list's array when deleting by index by x42005e1f · Pull Request #158602 · python/cpython · GitHub
Open Graph Title: gh-158592: Reallocate the list's array when deleting by index by x42005e1f · Pull Request #158602 · python/cpython
X Title: gh-158592: Reallocate the list's array when deleting by index by x42005e1f · Pull Request #158602 · python/cpython
Description: Fixes the linked issue with a simple one-line change, copy-pasted from list_pop_impl(). Ideally, the v == NULL branch of the list_ass_item_lock_held() function should be code-synchronized with the one mentioned, since the implementation of list_pop_impl() appears to be more efficient, but that is beyond the scope of this PR. Performance comparison: Details $ ./python -m pyperf timeit -s 'obj = []' 'obj.append(None); del obj[-1]' --duplicate 1000 ..................... Mean +- std dev: 19.3 ns +- 0.0 ns $ ./python -m pyperf timeit -s 'obj = [None]' 'obj.append(None); del obj[-1]' --duplicate 1000 ..................... Mean +- std dev: 19.3 ns +- 0.1 ns $ ./python -m pyperf timeit -s 'obj = []' 'obj.append(None); del obj[-1]' --duplicate 1000 ..................... Mean +- std dev: 50.3 ns +- 0.3 ns $ ./python -m pyperf timeit -s 'obj = [None]' 'obj.append(None); del obj[-1]' --duplicate 1000 ..................... Mean +- std dev: 27.1 ns +- 0.1 ns Benchmark before after 0-1 items 19.3 ns 50.3 ns: 2.61x slower 1-2 items 19.3 ns 27.1 ns: 1.40x slower The first case always reallocates the array, while the second case never reallocates the array (see #158602 (comment)). The results appear to be a performance regression, but it is important to understand what this change actually does. Namely, it simply restores the missed reallocation that other methods already perform (del list[slice], list.pop(), list.remove(), etc.)! If you are concerned about this, you should change the list_resize() implementation rather than making the collection non-shrinkable in terms of capacity. I decided not to add a regression test because it would depend on the exact behavior of the list_resize() function (specifically, when it decides to change the capacity), which would require updating the test whenever its condition changed. Issue: gh-158592
Open Graph Description: Fixes the linked issue with a simple one-line change, copy-pasted from list_pop_impl(). Ideally, the v == NULL branch of the list_ass_item_lock_held() function should be code-synchronized with the ...
X Description: Fixes the linked issue with a simple one-line change, copy-pasted from list_pop_impl(). Ideally, the v == NULL branch of the list_ass_item_lock_held() function should be code-synchronized with the ...
Opengraph URL: https://github.com/python/cpython/pull/158602
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,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-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:2d49e1d7-4455-75f7-3fb1-4e0878e5284b |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B1B8:2E7DFB:3055C4:3F9C75:6B02345B |
| html-safe-nonce | 0f0ce5559109128c0198c5824046e7721e6ddb0384f8bdc9f616bbf0b40d543f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMUI4OjJFN0RGQjozMDU1QzQ6M0Y5Qzc1OjZCMDIzNDVCIiwidmlzaXRvcl9pZCI6IjE0NDA0MzY4MzkyMTg1NTgwNDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4ad1abbd45a85c6453c112cbb5baee596573a2aa7e8a002d9c0fc922331b19ef |
| hovercard-subject-tag | pull_request:4717436144 |
| 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/158602/files |
| twitter:image | https://avatars.githubusercontent.com/u/141886287?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/141886287?s=400&v=4 |
| og:image:alt | Fixes the linked issue with a simple one-line change, copy-pasted from list_pop_impl(). Ideally, the v == NULL branch of the list_ass_item_lock_held() function should be code-synchronized with the ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width