-
Notifications
You must be signed in to change notification settings - Fork 111
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
Move value in put() #25
Comments
@dermojo as I understand after your fix, the values will be copied anyway but during the function call, as it is not reference anymore but value. So you first pass a value and then move that copied value to the list. |
@lamerman Sorry, I should have explained my change: Consider the following code (for a cache mapping an int to a string): It doesn't make a difference when the caller passes a reference to an existing object, because there still will be a copy, but in case of temporary/move the copy is avoided. |
@dermojo, In my view, the interface now looks complicated. User doesn't know that move happens internally unless he looks into the code. Can we implement a separate method for rvalues that has explicit interface and it's clear what will happen there? |
Moreover, a big problem is that for those who already use this library an update will cause additional move constructor involved. If you leave the PR as it is. |
I understand, although I think adding another overload for put() that takes an rvalue makes the API more complicated than having a single by-value method (and may introduce ambiguity). I'm not sure if I want to invest much time in this change (I don't need it, I just wanted to share a performance improvement). If you're worried about existing users of the code, feel free to reject the PR and leave the code as-is. That's fine with me. But I think the current version is the cleanest from an API point of view. |
I agree with you that something should be done in this direction. Currently the only way if your class is heavy-weight is smart pointers. So it should be done. |
Hi,
While performing some benchmarks I noticed that inserted values are copied, which reduces insert performance. I'll create a pull request to move values into the cache.
The text was updated successfully, but these errors were encountered: