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

Improve performance of array_inplace_repeat #91226

Closed
eendebakpt mannequin opened this issue Mar 19, 2022 · 3 comments
Closed

Improve performance of array_inplace_repeat #91226

eendebakpt mannequin opened this issue Mar 19, 2022 · 3 comments
Labels
3.11 bug and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@eendebakpt
Copy link
Mannequin

eendebakpt mannequin commented Mar 19, 2022

BPO 47070
Nosy @sweeneyde, @eendebakpt
PRs
  • bpo-47070: improve performance of array_inplace_repeat #31999
  • 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 = None
    created_at = <Date 2022-03-19.21:27:17.989>
    labels = ['interpreter-core', '3.11', 'performance']
    title = 'Improve performance of array_inplace_repeat'
    updated_at = <Date 2022-03-28.08:44:05.124>
    user = 'https://github.com/eendebakpt'

    bugs.python.org fields:

    activity = <Date 2022-03-28.08:44:05.124>
    actor = 'Dennis Sweeney'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2022-03-19.21:27:17.989>
    creator = 'pieter.eendebak'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 47070
    keywords = ['patch']
    message_count = 3.0
    messages = ['415572', '415584', '416152']
    nosy_count = 2.0
    nosy_names = ['Dennis Sweeney', 'pieter.eendebak']
    pr_nums = ['31999']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue47070'
    versions = ['Python 3.11']

    @eendebakpt
    Copy link
    Mannequin Author

    eendebakpt mannequin commented Mar 19, 2022

    The array_inplace_repeat is inefficient for small arrays and a high number of repeats. This can be improved by using the same approach as in https://bugs.python.org/issue47005

    @eendebakpt eendebakpt mannequin added 3.11 bug and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage labels Mar 19, 2022
    @sweeneyde
    Copy link
    Member

    I'd bet we could add a couple of utility functions that could be used in multiple places, to keep the "trick" all in one place. Something like

    void
    _PyBytes_RepeatInPlace(char **buffer, size_t start_len, size_t end_len)
    {
        // Repeatedly double.
        size_t copied = start_len;
        while (copied < end_len) {
            size_t to_copy = Py_MIN(copied, end_len - copied);
            memcpy(buffer + copied, buffer, to_copy);
            copied += to_copy;
        }
    }
    
    void
    _PyBytes_Repeat(char *dest, size_t len_dest,
                    const char *src, size_t len_src)
    {
        // XXX maybe handle zero lengths
        // XXX maybe use memset for len_src == 1
        memcpy(dest, src, len_src);
        _PyBytes_RepeatInPlace(dest, len_src, len_dest);
    }

    @sweeneyde
    Copy link
    Member

    New changeset 850687d by Pieter Eendebak in branch 'main':
    bpo-47070: Add _PyBytes_Repeat() (GH-31999)
    850687d

    @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
    3.11 bug and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants