classification
Title: copy.copy(bytes) is slow
Type: performance Stage: resolved
Components: Library (Lib) Versions: Python 3.5, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: frankmillman, haypo, peter.otten, pitrou, python-dev, r.david.murray, yselivanov
Priority: normal Keywords: patch

Created on 2014-02-27 08:58 by frankmillman, last changed 2014-02-27 23:35 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
copy_bytes.patch peter.otten, 2014-02-27 09:40 review
Messages (12)
msg212340 - (view) Author: Frank Millman (frankmillman) Date: 2014-02-27 08:58
Using copy.copy on a byte string returns a new copy instead of the original immutable object. Using copy.deepcopy returns the original, as expected. Testing with timeit, copy.copy is much slower than copy.deepcopy.

>>> import copy
>>>
>>> a = 'a'*1000  # string
>>> copy.copy(a) is a
True
>>> copy.deepcopy(a) is a
True
>>>
>>> b = b'b'*1000  # bytes
>>> copy.copy(b) is b
False
>>> copy.deepcopy(b) is b
True
msg212344 - (view) Author: Peter Otten (peter.otten) * Date: 2014-02-27 09:40
Assuming that the current behaviour is by accident here's a patch that adds the bytes type to the _copy_dispatch registry.
msg212345 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2014-02-27 09:46
bytes is immutable, I don't why we would duplicate it.
msg212354 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-02-27 14:02
We probably just forgot to add it when the bytes type was added, and there was of course no test that would fail since it was a new type.
msg212377 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-02-27 19:27
Thanks for the patch, Peter. Could you sign a contributor's agreement? You can do so online at http://www.python.org/psf/contrib/contrib-form/
msg212383 - (view) Author: Peter Otten (peter.otten) * Date: 2014-02-27 20:39
I did sign today (and received the confirmation email).
msg212388 - (view) Author: Roundup Robot (python-dev) Date: 2014-02-27 21:16
New changeset c2523bca50d7 by Antoine Pitrou in branch 'default':
Issue #20791: copy.copy() now doesn't make a copy when the input is a bytes object.  Initial patch by Peter Otten.
http://hg.python.org/cpython/rev/c2523bca50d7
msg212389 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-02-27 21:16
Ok, thank you! This will be in 3.4.1 and 3.5.
msg212392 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2014-02-27 22:53
Why not fixing this bug in Python 3.3 too?
msg212393 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-02-27 22:54
Is Python 3.3 still allowing bug fixes?
If yes, this is a good idea. Do you want to backport it?
msg212394 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-02-27 23:04
3.3 will get fixes until its final release, which will be some time after the release of 3.4.0.
msg212395 - (view) Author: Roundup Robot (python-dev) Date: 2014-02-27 23:35
New changeset b3fb7828b6fc by Antoine Pitrou in branch '3.3':
Issue #20791: copy.copy() now doesn't make a copy when the input is a bytes object.  Initial patch by Peter Otten.
http://hg.python.org/cpython/rev/b3fb7828b6fc
History
Date User Action Args
2014-02-27 23:35:06python-devsetmessages: + msg212395
2014-02-27 23:04:29r.david.murraysetmessages: + msg212394
2014-02-27 22:54:13pitrousetmessages: + msg212393
2014-02-27 22:53:03hayposetmessages: + msg212392
2014-02-27 21:16:28pitrousetstatus: open -> closed
resolution: fixed
messages: + msg212389

stage: patch review -> resolved
2014-02-27 21:16:04python-devsetnosy: + python-dev
messages: + msg212388
2014-02-27 20:39:15peter.ottensetmessages: + msg212383
2014-02-27 19:27:29pitrousetversions: - Python 3.3
nosy: + pitrou

messages: + msg212377

stage: patch review
2014-02-27 14:02:23r.david.murraysetnosy: + r.david.murray

messages: + msg212354
versions: + Python 3.4, Python 3.5
2014-02-27 13:35:08yselivanovsetnosy: + yselivanov
2014-02-27 09:46:57hayposetnosy: + haypo
messages: + msg212345
2014-02-27 09:40:31peter.ottensetfiles: + copy_bytes.patch

nosy: + peter.otten
messages: + msg212344

keywords: + patch
2014-02-27 08:58:03frankmillmancreate