-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Issue #2147: avoid copies on non-small writes #2169
Conversation
I haven't read the full diff yet, but in #2008 we found that using |
I've checked that this PR is immune to #2008. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good - I'd like to see some basic docstrings on the new methods and I have a few naming nits, but otherwise I think it's ready to go.
tornado/iostream.py
Outdated
elif size > 0: | ||
if self._buffers: | ||
is_large, b = self._buffers[-1] | ||
is_large = is_large or len(b) >= self._large_buf_threshold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_large
is doing a lot of different things here. I think it woudl be more clear if this were
if self._buffers:
is_memview, b = self._buffers[-1]
new_buf = is_memview or len(b) > self._large_buf_threshold
else:
new_buf = True
tornado/iostream.py
Outdated
def peek(self, size): | ||
assert size > 0 | ||
try: | ||
is_large, b = self._buffers[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_memview
here as well.
tornado/iostream.py
Outdated
else: | ||
return memoryview(b)[pos:pos + size] | ||
|
||
def skip(self, size): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this advance
or consume
?
There was a hang in the latest Travis build on 2.7. I'm not able to reproduce locally. |
Thanks! |
(I reran the travis build and it passed, so the hang was just a fluke) |
Improves performance by 35% on the following benchmark: #2147 (comment)
Makes
demos/benchmark/benchmark.py
about 2% slower.(split from #2166)