-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Speed-up in array_repeat() #44066
Comments
Use iterative doubling when extending the old array. |
Logged In: YES Have you benchmarked this for repeats found "in the wild" to |
Logged In: YES I wrote this code for a university project I'm doing myself, If you mean, have I benchmarked it with other people's code, |
Logged In: YES This patch is basically fine. Will neaten it up to match |
Logged In: YES I'd assumed Python *didn't* double the size when resizing an array because of how much memory that wastes. May I suggest trying it with a multiplier of 1.5x, and comparing both CPU time and memory consumption? I find for these things that 1.5x is nearly as fast and wastes far less memory. |
Logged In: YES This patch has nothing to do with array resizing. It has to |
This proposal is basically fine. The patch should be re-worked to model as closely as possible the code for string_repeat in Objects/stringobject.c (revisions 30616 and 30368 provide the details). That code is known to work and to have provided a meaningful speed-up. |
This one is easy if someone wants to take a crack at it. |
Looking at stringobject.c:1034: i = 0;
if (i < size) {
Py_MEMCPY(op->ob_sval, a->ob_sval, Py_SIZE(a));
i = Py_SIZE(a);
}
while (i < size) {
j = (i <= size-i) ? i : size-i;
Py_MEMCPY(op->ob_sval+i, op->ob_sval, j);
i += j;
}
return (PyObject *) op; Do I miss something or the first condition "if (i < size)" is Wouldn't it be clearer to write if (size == 0) |
Attached patch (bpo-1569291.diff) reimplements the optimization by I see two remaining issues which in my view should be addressed separately:
|
I forgot to mention that I added a unit test to cover the special case |
Georg, do you want to take it from here. |
There are lots of positive comments on this issue, please can core developers take a bit of time to have a look and say yes or no. |
Uh, this slipped under my radar. Let's see if I get the chance to look at it at the core sprint next week. |
I changed the patch to look more like unicode_repeat (which addresses Alex' point #2) and committed in r87022. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: