This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Improve performance of array_inplace_repeat
Type: performance Stage: patch review
Components: Interpreter Core Versions: Python 3.11
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, pieter.eendebak
Priority: normal Keywords: patch

Created on 2022-03-19 21:27 by pieter.eendebak, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 31999 merged pieter.eendebak, 2022-03-19 21:47
Messages (3)
msg415572 - (view) Author: Pieter Eendebak (pieter.eendebak) * Date: 2022-03-19 21:27
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
msg415584 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-03-19 23:09
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

_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;

_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);
msg416152 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2022-03-28 08:44
New changeset 850687df47b03e98c1433e6e70e71a8921eb4454 by Pieter Eendebak in branch 'main':
bpo-47070: Add _PyBytes_Repeat() (GH-31999)
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91226
2022-03-28 08:44:05Dennis Sweeneysetmessages: + msg416152
2022-03-19 23:09:13Dennis Sweeneysetnosy: + Dennis Sweeney
messages: + msg415584
2022-03-19 21:47:14pieter.eendebaksetkeywords: + patch
stage: patch review
pull_requests: + pull_request30088
2022-03-19 21:27:17pieter.eendebakcreate