Skip to content
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

copy.copy(bytes) is slow #64990

Closed
frankmillman mannequin opened this issue Feb 27, 2014 · 12 comments
Closed

copy.copy(bytes) is slow #64990

frankmillman mannequin opened this issue Feb 27, 2014 · 12 comments
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@frankmillman
Copy link
Mannequin

frankmillman mannequin commented Feb 27, 2014

BPO 20791
Nosy @pitrou, @vstinner, @bitdancer, @1st1
Files
  • copy_bytes.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2014-02-27.21:16:28.389>
    created_at = <Date 2014-02-27.08:58:03.176>
    labels = ['library', 'performance']
    title = 'copy.copy(bytes) is slow'
    updated_at = <Date 2014-02-27.23:35:06.626>
    user = 'https://bugs.python.org/frankmillman'

    bugs.python.org fields:

    activity = <Date 2014-02-27.23:35:06.626>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-02-27.21:16:28.389>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2014-02-27.08:58:03.176>
    creator = 'frankmillman'
    dependencies = []
    files = ['34244']
    hgrepos = []
    issue_num = 20791
    keywords = ['patch']
    message_count = 12.0
    messages = ['212340', '212344', '212345', '212354', '212377', '212383', '212388', '212389', '212392', '212393', '212394', '212395']
    nosy_count = 7.0
    nosy_names = ['peter.otten', 'pitrou', 'vstinner', 'frankmillman', 'r.david.murray', 'python-dev', 'yselivanov']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue20791'
    versions = ['Python 3.4', 'Python 3.5']

    @frankmillman
    Copy link
    Mannequin Author

    frankmillman mannequin commented Feb 27, 2014

    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

    @frankmillman frankmillman mannequin added stdlib Python modules in the Lib dir performance Performance or resource usage labels Feb 27, 2014
    @peterotten
    Copy link
    Mannequin

    peterotten mannequin commented Feb 27, 2014

    Assuming that the current behaviour is by accident here's a patch that adds the bytes type to the _copy_dispatch registry.

    @vstinner
    Copy link
    Member

    bytes is immutable, I don't why we would duplicate it.

    @bitdancer
    Copy link
    Member

    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.

    @pitrou
    Copy link
    Member

    pitrou commented Feb 27, 2014

    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/

    @peterotten
    Copy link
    Mannequin

    peterotten mannequin commented Feb 27, 2014

    I did sign today (and received the confirmation email).

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 27, 2014

    New changeset c2523bca50d7 by Antoine Pitrou in branch 'default':
    Issue bpo-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

    @pitrou
    Copy link
    Member

    pitrou commented Feb 27, 2014

    Ok, thank you! This will be in 3.4.1 and 3.5.

    @pitrou pitrou closed this as completed Feb 27, 2014
    @vstinner
    Copy link
    Member

    Why not fixing this bug in Python 3.3 too?

    @pitrou
    Copy link
    Member

    pitrou commented Feb 27, 2014

    Is Python 3.3 still allowing bug fixes?
    If yes, this is a good idea. Do you want to backport it?

    @bitdancer
    Copy link
    Member

    3.3 will get fixes until its final release, which will be some time after the release of 3.4.0.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 27, 2014

    New changeset b3fb7828b6fc by Antoine Pitrou in branch '3.3':
    Issue bpo-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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    performance Performance or resource usage stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants