-
Notifications
You must be signed in to change notification settings - Fork 230
Use Iterator<Item = u8>
instead of Expander
#1317
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
base: master
Are you sure you want to change the base?
Conversation
adad13e
to
9ed6117
Compare
make hash_to_field output an array use primitive array instead of `hybrid_array::Array` fix: all uses of hash_to_field in other crates
9ed6117
to
8735cba
Compare
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'm not terribly concerned about the slowdown. Overall executing the whole hash2curve operation is quite expensive compared to the Expander
part, I would assume.
However I'm uncertain now what we are trying to achieve here. We are getting rid of a trait in favor of worse performance and improving the feedback (returning None
when we are done).
In hindsight, what we want to model is the Read
API. This would be an accurate representation to whats going on there. Unfortunately the Read
trait isn't available on no_std.
I will make a PR to propose an alternative, then we can do a comparison and see what we get.
let ell = u8::try_from(usize::from(len_in_bytes.get()).div_ceil(b_in_bytes)) | ||
.expect("should never pass the previous check"); |
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.
Lets turn this into a debug_assert!
.
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 think the logic here is succinct enough to not need a dbg assert. Since len_in_bytes <= 255 * b_in_bytes
, len_in_bytes / b_in_bytes <= 255
.
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.
Seems fine to me!
See #1318. |
Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: daxpedda <daxpedda@gmail.com>
#1318 raises the concern that the |
Yes please, removing that lifetime from |
The trait no longer has an input lifetime, it has an associated type |
Discussed in #1295.
Changes
Expander
trait removed in favor ofIterator
.ExpandMsgXmd
andExpandMsgXof
stop generating bytes after having reachedlen_in_bytes
.ExpandMsgXmd
andExpandMsgXof
are themselves the "expanders", instead of having anExpander
associated type.Regression
On small workloads (
len_in_bytes < 256
), both xmd and xof expanders are ~ 20% slower withIterator
than withExpander
. On the largest workloads (len_in_bytes = 4k
), xmd is 50% slower and xof is 100% slower with iterator. I thinkExpandMsgXof
could be made equally as fast ifXofReader
allowed a method that generates an Iterator over its inner buffer, just like howExpandMsgXmd
is implemented. I also think that adding bound checks (like there should have been) onExpander
would cause similar slow downs on small workloads.Metrics
small (frequent use case):
large:
I did not include the benchmarks in the PR because I did not want to add criterion as a
dev-dependency
. Let me know if you want me to add them.I let the maintainers decide whether this regression is worth it.