Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

shelve:Shelf.clear() has very poor performance #107089

Closed
Labels
performancePerformance or resource usage
@jtcave

Description

@jtcave

Bug report

Calling theclear method on ashelve.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.

importosimportshelveimporttempfilewithtempfile.TemporaryDirectory()astempdir:filename=os.path.join(tempdir,"test-shelf")withshelve.open(filename)asdb:items= {str(x):xforxinrange(10000)}db.update(items)db.clear()print("ok")

On my M2 Mac Mini, this script takes about 2.1 seconds.

james@iris ~ % time python shelve-clear-test.pyokpython shelve-clear-test.py  1.18s user 0.92s system 99% cpu 2.100 total

On a Debian VPS:

james@asteroid:~$ time python3 shelve-clear-test.py okreal0m43.665suser0m34.330ssys0m9.107s

Your environment

  • CPython versions tested on
    • 3.11.2
    • 3.11.4
    • cpython/main branch
  • Operating system and architecture
    • macOS/arm64 13.4.1
    • Debian/x86_64 12.1

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp