-
Notifications
You must be signed in to change notification settings - Fork 53
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
Use pass-by-copy for Hrp when possible #148
Use pass-by-copy for Hrp when possible #148
Conversation
7ba372f
to
c65666e
Compare
I feel like if it implements What threshold do you have in mind for copying by reference vs copy? |
I thought a struct was
I had 32 bytes in mind, based on discussion a few years ago about passing hashes by copy. |
You need to explicitly derive 32 bytes seems a little small, though I could believe that that's roughly where the performance starts to equal out. In this case though I don't think the performance benefit (if there is one) outweighs the loss of ergonomics. It's not like anybody would ever be manipulating |
I'm convinced. I'll change this to "remove pass-by-reference" |
c65666e
to
608ead7
Compare
Hrp
by reference608ead7
to
6cfd22d
Compare
We currently have some code that uses pass-by-reference and some that uses pass-by-copy. Further investigation shows that when messing with iterators we have to have a reference to the `Hrp` so that the iterator has somewhere in memory to point to while iterating. The iterator API is intentionally low level, we can make the higher level APIs more ergonomic by using pass-by-copy.
6cfd22d
to
faf8651
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.
ACK faf8651
Regarding |
@Kixunil it also shouldn't be |
That to me feels like kind of an abuse of the type system but since there's
What is the justification for this? The compiler will produce exactly the same amount of |
If |
Which will also produce memcpy calls whenever they need owned value inside the function. I think this is not something for libraries to decide, it's better to have lints and such if any actual performance benefit can be identified. |
You can't get an owned value from a borrow of a non-
I believe we're only making this decision for our own internal code. And for our public APIs we have to decide whether to take a value by reference or by value. |
You can if it's
I'd be fine with this. |
We currently have some code that uses pass-by-reference and some that uses pass-by-copy.
Further investigation shows that when messing with iterators we have to have a reference to the
Hrp
so that the iterator has somewhere in memory to point to while iterating.The iterator API is intentionally low level, we can make the higher level APIs more ergonomic by using pass-by-copy.