-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add faster implementation of _IonNature.ion_hash #22
Conversation
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.
Looks pretty good!
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 is very nice.
return _bytes.replace(bytes([_ESCAPE_BYTE]), bytes([_ESCAPE_BYTE, _ESCAPE_BYTE])) \ | ||
.replace(_BEGIN_MARKER, bytes([_ESCAPE_BYTE, _BEGIN_MARKER_BYTE])) \ | ||
.replace(_END_MARKER, bytes([_ESCAPE_BYTE, _END_MARKER_BYTE])) |
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.
Should we avoid recomputing bytes([...])
on each call by storing the values?
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.
I don't know. I have also heard that looking up non-local values can be expensive in Python, and if we want to compute once and store the value, then it would need to be a non-local value. I'll create a followup issue to see if it would improve performance.
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.
That's fine with me, although it does seem like a simple enough thing to try given that you already have a basic perf testing setup.
Issue #, if available:
Not necessarily a fix; at least an improvement for #21
Description of changes:
New implementation of
.ion_hash()
that does away with the overhead of instantiatingion_writer
s. As part of this change, I improved the performance of the_escape()
function, which has the side effect of also benefitting theion_hash_reader
and theion_hash_writer
.I did some very informal performance testing using this script.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.