-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
shelve: Shelf.clear()
has very poor performance
#107089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
performance
Performance or resource usage
Comments
jtcave
added a commit
to jtcave/cpython
that referenced
this issue
Jul 23, 2023
The clear method used to be implemented by inheriting a mix-in from the MutableMapping ABC. It was a poor fit for shelves, and a better implementation is now in place
How much of the 2.1 seconds is the |
Virtually all of it. The example script running on my branch takes milliseconds.
|
jtcave
added a commit
to jtcave/cpython
that referenced
this issue
Jul 23, 2023
The clear method used to be implemented by inheriting a mix-in from the MutableMapping ABC. It was a poor fit for shelves, and a better implementation is now in place
jtcave
added a commit
to jtcave/cpython
that referenced
this issue
Jul 23, 2023
The prior performance fix could have disrupted non-dbm subclasses of Shelf. The code has been refactored to put the clear logic in the DbfilenameShelf class, which can assume the backing object is a dbm object. The code still attempts to call the clear method on the backing object (see pythongh-107122).
jtcave
added a commit
to jtcave/cpython
that referenced
this issue
Jul 24, 2023
Because pythongh-107089 is peculiar to implementation details of dbm objects, it would be less disruptive to implement it in the DbfilenameShelf class, which is used for calls to shelve.open. Since it is known that the backing object is specifically one of the dbm objects, its clear method (see pythongh-107122) can be used with no fallback code.
jtcave
added a commit
to jtcave/cpython
that referenced
this issue
Jul 27, 2023
The clear method used to be implemented by inheriting a mix-in from the MutableMapping ABC. It was a poor fit for shelves, and a better implementation is now in place
jtcave
added a commit
to jtcave/cpython
that referenced
this issue
Jul 27, 2023
Because pythongh-107089 is peculiar to implementation details of dbm objects, it would be less disruptive to implement it in the DbfilenameShelf class, which is used for calls to shelve.open. Since it is known that the backing object is specifically one of the dbm objects, its clear method (see pythongh-107122) can be used with no fallback code.
jtcave
added a commit
to jtcave/cpython
that referenced
this issue
Jul 27, 2023
The clear method used to be implemented by inheriting a mix-in from the MutableMapping ABC. It was a poor fit for shelves, and a better implementation is now in place
jtcave
added a commit
to jtcave/cpython
that referenced
this issue
Jul 27, 2023
Because pythongh-107089 is peculiar to implementation details of dbm objects, it would be less disruptive to implement it in the DbfilenameShelf class, which is used for calls to shelve.open. Since it is known that the backing object is specifically one of the dbm objects, its clear method (see pythongh-107122) can be used with no fallback code.
jtcave
added a commit
to jtcave/cpython
that referenced
this issue
Jul 28, 2023
The clear method used to be implemented by inheriting a mix-in from the MutableMapping ABC. It was a poor fit for shelves, and a better implementation is now in place
jtcave
added a commit
to jtcave/cpython
that referenced
this issue
Jul 28, 2023
Because pythongh-107089 is peculiar to implementation details of dbm objects, it would be less disruptive to implement it in the DbfilenameShelf class, which is used for calls to shelve.open. Since it is known that the backing object is specifically one of the dbm objects, its clear method (see pythongh-107122) can be used with no fallback code.
corona10
pushed a commit
that referenced
this issue
Jul 29, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
Calling the
clear
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.
On my M2 Mac Mini, this script takes about 2.1 seconds.
On a Debian VPS:
Your environment
Linked PRs
The text was updated successfully, but these errors were encountered: