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
subprocess.communicate() should use a memoryview #63705
Comments
The following code copies data, whereas the copy can be avoided using a memory view: chunk = self._input[self._input_offset:self._input_offset + _PIPE_BUF]
self._input_offset += os.write(key.fd, chunk) It should be replaced with: input_view = memoryview(self._input)
...
chunk = input_view[self._input_offset:self._input_offset + _PIPE_BUF]
self._input_offset += os.write(key.fd, chunk) This issue is a reminder for one of my comment of issue bpo-18923. |
Attached subprocess_memoryview.patch uses a memoryview() to avoid memory copies. The behaviour is undefined if two threads share the same Popen object and call the communicate() method at the same time. But I'm not sure that Popen is thread safe, it doesn't use any lock. |
Hi, why does your patch change listobject.c? |
Oops, the change is unrelated (bpo-19578). |
What is a performance for small chunks? |
I have no idea. Does it matter? |
I don't know. But a function call have a cost. |
New patch without the unwanted change in listobject.c. |
I'm with Serhiy here. |
Could someone with a dual-core machine try the attached simplistic |
On a quad-core machine:
$ time ./python test_sub.py
0.39263957000002847 real 0m0.521s
$ time ./python test_sub.py
0.3856174530001226 real 0m0.516s |
Best of 10 runs. Unpatched: 3.91057508099766 |
Impressive speedup :-) |
New changeset 44948f5bdc12 by Gregory P. Smith in branch '3.3': New changeset 5379bba2fb21 by Gregory P. Smith in branch 'default': |
fwiw, this patch made sense. using test_sub.py on my dual-core amd64 box with an opt build is saw the times drop from ~0.90-0.97 to ~0.75-0.8. more speedup than i was really anticipating for this use case. it probably depends upon what the value of _PIPE_BUF is on your system. |
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: