-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Support memoryview encoding (as a no-op) #1266
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
Conversation
|
Looks like Py27 is having an issue with this. Also can we move the test to the test_encoding.py module? I'd prefer a simple test that persists the a |
Oops! I'm not well-practiced maintaining python version compatibility but I'll give it a shot.
Yes this makes sense, I had a feeling it wasn't the best place for the test code. |
|
@Cody-G Does If If |
|
Tests are now passing on all Python versions. I'm not sure why, but the python 2.7 tests seem to execute this branch but I think the other python versions tests do not. The problem occurs when we try to do a string join on a |
|
Oh I think we posted at the same time, let me read your post. |
Yes it does. With my last commit I compromised on that for small objects (less than the hard-coded size limit)
I was pretty sure this does copy the memory, but let me double check that |
|
|
|
It looks like this PR always calls It seems like the way to do this is to make a special case for for arg in imap(self.encoder.encode, args):
arg_length = len(arg)
if len(buff) > buffer_cutoff or arg_length > buffer_cutoff or isinstance(arg, memoryview):
# same code that exists currentlyThis will append the current buffer plus the length of the memoryview to the output list, and then append the memoryview directly without a copy. Note that I haven't actually tested this. If you could that would be quite helpful. Thanks! |
Indeed it is, and this PR in its current form fails to avoid it. I wasn't sure how much to respect the current optimization of joining small strings before sending over the socket. In our company fork I took the more aggressive approach of never converting memoryviews to bytes, which is I think what you're suggesting. If you're ok with that approach I can update this PR / make a new one next week. Would definitely like to get this in somehow so we don't need to maintain our own fork. Thanks for your attention on this! |
|
Superseded by #1285 |
Pull Request check-list
Please make sure to review and check all of these items:
$ toxpass with this change (including linting)?NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Description of change
Supports passing memoryviews to redis-py as outlined in #1265