Title: shelve: `Shelf.clear()` has very poor performance · Issue #107089 · python/cpython · GitHub
Open Graph Title: shelve: `Shelf.clear()` has very poor performance · Issue #107089 · python/cpython
X Title: shelve: `Shelf.clear()` has very poor performance · Issue #107089 · python/cpython
Description: Bug report Calling the clear method on a shelve.Shelf object takes a very long time on databases that have thousands of entries. It can be seen in this script, which creates a database with 10,000 entries and immediately clears it. impor...
Open Graph Description: Bug report Calling the clear method on a shelve.Shelf object takes a very long time on databases that have thousands of entries. It can be seen in this script, which creates a database with 10,000 ...
X Description: Bug report Calling the clear method on a shelve.Shelf object takes a very long time on databases that have thousands of entries. It can be seen in this script, which creates a database with 10,000 ...
Opengraph URL: https://github.com/python/cpython/issues/107089
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"shelve: `Shelf.clear()` has very poor performance","articleBody":"# Bug report\r\n\r\nCalling the `clear` method on a `shelve.Shelf` object takes a very long time on databases that have thousands of entries.\r\n\r\nIt can be seen in this script, which creates a database with 10,000 entries and immediately clears it.\r\n\r\n```python\r\nimport os\r\nimport shelve\r\nimport tempfile\r\n\r\nwith tempfile.TemporaryDirectory() as tempdir:\r\n filename = os.path.join(tempdir, \"test-shelf\")\r\n with shelve.open(filename) as db:\r\n items = {str(x):x for x in range(10000)}\r\n db.update(items)\r\n db.clear()\r\nprint(\"ok\")\r\n\r\n```\r\n\r\nOn my M2 Mac Mini, this script takes about 2.1 seconds.\r\n```\r\njames@iris ~ % time python shelve-clear-test.py\r\nok\r\npython shelve-clear-test.py 1.18s user 0.92s system 99% cpu 2.100 total\r\n```\r\n\r\nOn a Debian VPS:\r\n```\r\njames@asteroid:~$ time python3 shelve-clear-test.py \r\nok\r\n\r\nreal\t0m43.665s\r\nuser\t0m34.330s\r\nsys\t0m9.107s\r\n```\r\n\r\n# Your environment\r\n\r\n\u003c!-- Include as many relevant details as possible about the environment you experienced the bug in --\u003e\r\n\r\n- CPython versions tested on\r\n - 3.11.2\r\n - 3.11.4\r\n - cpython/main branch\r\n- Operating system and architecture\r\n - macOS/arm64 13.4.1\r\n - Debian/x86_64 12.1\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-107090\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/jtcave","@type":"Person","name":"jtcave"},"datePublished":"2023-07-23T01:47:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/107089/cpython/issues/107089"}
| 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:83c68a2d-165b-270e-da7c-bc4bd3faad7a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E8A:320F8E:1D29260:27C92F2:696ABCFD |
| html-safe-nonce | 8a8afc28d6a6a086ff5d763d10a0731981e118f2a87a712308f35327228fb40a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RThBOjMyMEY4RToxRDI5MjYwOjI3QzkyRjI6Njk2QUJDRkQiLCJ2aXNpdG9yX2lkIjoiNTkwNTk4NTExMzYwOTEyNTExNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 99966f6e3d2d0d3490d80868220ad9a70cfe054323a539e5fc57e98db334371c |
| hovercard-subject-tag | issue:1816953459 |
| 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/107089/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a28697574ba6a498dd51736cc90295604476af52206f0f328193e90853e8021c/python/cpython/issues/107089 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a28697574ba6a498dd51736cc90295604476af52206f0f328193e90853e8021c/python/cpython/issues/107089 |
| og:image:alt | Bug report Calling the clear method on a shelve.Shelf object takes a very long time on databases that have thousands of entries. It can be seen in this script, which creates a database with 10,000 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jtcave |
| hostname | github.com |
| expected-hostname | github.com |
| None | 46ce962e0e18113ea447391b6ace8b02d4d2861e57b4fbab3658698f73d8855b |
| 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 | 30300f30bb3949de255e84a146706a3bdb5c19c9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width