You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
I reviewed the second one, and I thought it's actually quite ready to be merged. Now I'm a bit lost between two separate PRs fixing same thing in different ways.
Let's discuss both PRs in this one issue and decide which one is the way to go.
FWIW I've updated uvloop quite a while ago to avoid using custom bytearray buffers, preferring the writev sys call instead.
First of all, bytearray based buffer is used already, for most transports except _UnixWritePipeTransport. #385 just uses bytearray in _UnixWritePipeTransport too.
bytearray-based buffer
Pros:
Simple implementation.
Faster for small data.
.write(data) raises TypeError when data is not bytes-like memoryview. (e.g. memoryview(array.array('H', [1,2,3,4]))
Caller can reuse bytearray buffer passed to .write().
Easy to use bytearray-like, more efficient buffer implemented in C in the future.
As for #339 -- I feel a bit uneasy about it. I want asyncio to be fast in all use cases, but the PR is invasive and makes the code much more complex. An ideal solution would be to adaptively use bytearray to aggregate small writes in one buffer, and use vectorized writes for series of big bytes objects.
I'm wondering if we can design a nice fast buffer abstraction to do this. It should be separated from IO, and thoroughly tested. Then we can add os.writev for unix selector loop that would use the buffer.
User can't reuse bytearray passed to .write(). If user did it, they encounter bug which is rarely reproducible and hard to debug.
This is something we need to fix if we are to merge #339. A quick fix is it convert anything that's not bytes to bytes (if the first try-write fails with a BlockingIOError).
Activity
methane commentedon Jul 28, 2016
First of all, bytearray based buffer is used already, for most transports except
_UnixWritePipeTransport.#385 just uses bytearray in
_UnixWritePipeTransporttoo.bytearray-based buffer
Pros:
.write(data)raises TypeError when data is not bytes-like memoryview. (e.g.memoryview(array.array('H', [1,2,3,4])).write().Cons:
#339
Pros:
Cons:
sendmsgon Windows)..write(). If user did it, they encounter bug which is rarely reproducible and hard to debug._write_ready()may raise TypeError, instead ofwrite().Summary of benchmark
From #339 (comment)
small data:
large data:
1st1 commentedon Aug 2, 2016
@methane @socketpair Alright, I think we should first merge #385.
As for #339 -- I feel a bit uneasy about it. I want asyncio to be fast in all use cases, but the PR is invasive and makes the code much more complex. An ideal solution would be to adaptively use bytearray to aggregate small writes in one buffer, and use vectorized writes for series of big
bytesobjects.I'm wondering if we can design a nice fast buffer abstraction to do this. It should be separated from IO, and thoroughly tested. Then we can add
os.writevfor unix selector loop that would use the buffer.This is something we need to fix if we are to merge #339. A quick fix is it convert anything that's not bytes to bytes (if the first try-write fails with a BlockingIOError).
socketpair commentedon Aug 2, 2016
assertSequenceEqual)writev()variant.OK ?
methane commentedon Aug 3, 2016
I will prototype my idea, faster buffer implementation.
But I hope faster future implementation is reviewd
next Python 3.6 alpha.
1st1 commentedon Aug 3, 2016
@socketpair If you can simplify the tests then sure, make a PR.
@methane If I don't review the C Future patch this week feel free to ping me again on the issue tracker sometime next week.
1st1 commentedon Sep 15, 2016
Alright, I merged #385 in 6f8f833. Does it mean we can close #339? I think we can still add vectorized writes in 3.7.
socketpair commentedon Sep 16, 2016
Well, please don't close. Seems I will find a time to fix/refactor that
1st1 commentedon Oct 5, 2016
Closing this issue now.