-
Notifications
You must be signed in to change notification settings - Fork 463
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
Operators only implemented on references #57
Comments
If I understand, the benchmarks suffer if you pass these structures by value, but maybe one can tweak that with optimizations modes, etc. In particular, passing by value permits the recipient to mutate the value, so you stack space optimizations might inhibit doing a pass by reference behind the scenes. I'd also think making the operators |
When we implemented the arithmetic ops for I didn't think that it would be possible to work around this, but it seems like @burdges' suggestion might work, at least on that toy example. So, to answer your original question, @UnlawfulMonad, if there were implementations of the arithmetic ops that didn't require borrows but were just as fast, we would be happy to take that PR. |
Hi @UnlawfulMonad! As @hdevalence said, we'd be stoked to take a patch for this, provided it doesn't slow anything down by introducing needless copies everywhere. If you want to implement this, my suggestion for the steps would be:
@UnlawfulMonad Would you like me to assign you to this issue? |
Hi @isislovecruft and @hdevalence! Thanks for the suggestions. I'll get on this next week and update this issue with my progress. I assumed that inlining would already be occurring if the call by value variant were simply wrapping the call by reference versions. Sidenote: Eye of Sauron is a great name for those things. :) |
@UnlawfulMonad Awesome, thanks! It appears like if we add (Also I used to work at the FreeGeek in Portland! It is an excellent project!) |
@isislovecruft Is code bloat not a concern at that point? Sorry for the lack of progress. It's been a hectic couple of weeks. (And that's awesome! Agreed, it's an awesome project!) |
Alright. Here are my results: All readings with rustc version Baseline from commit 97d6974:
With
With
Isolating a couple of the tests we get:
Note: the My assembly-fu isn't at the point where I can tell exactly what changed between runs but a cursory look suggests that it's very similar if not identical. Are these acceptable results? |
I started looking at this using cargo benchcmp on a machine with Turbo Boost disabled, so that the timings are actually consistent. I'm not entirely clear on what's going on, but hopefully I can get a clearer picture on the weekend or next week (I just wanted to note that I didn't forget about it). |
I compared the existing implementation with two variants of this trick: first, just having Roughly speaking, the results I got were a slight across-the-board decline in performance for the first option, which ends up inserting a bunch of extra copies. For the second option, there's a slight increase in performance for some functions, and some microbenchmarks, but there's a decrease in performance for the inversion used in decompression. (I believe this is because it's inlined all ~260 field operations). What I suspect is happening here is that the extra inline annotations are interacting with the cost model in unexpected and not always positive ways. So while, on a single example, using However, for point operations, which are what people who use |
Hmm. I'm interested in the idea of arithmetic operators behaving like operator |
There is more serious discussion on that topic now in rust-lang/rfcs#2147 |
Just to circle back on this, the refactoring in #86 more cleanly separates the internal API from the external API. I think the fix for this issue is to just implement operators for both |
Closing this issue since it's fixed in #101 |
Rand 0.6 version bump
I've noticed that operators on
ExtendedPoint
and the like are only implemented on&'a ExtendedPoint
. Is there any reason for a PR that also implemented them for the concrete types wouldn't be accepted? The types are already copy and as far as I know the compile is better at reasoning about the code when there isn't explicit memory (i.e. a reference) involved.The text was updated successfully, but these errors were encountered: