-
Notifications
You must be signed in to change notification settings - Fork 19
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
Excessive cloning in Stream::fold #105
Comments
could remove one clone here: wolfiestyle@d18ed3a But it seems that the problem comes from sampling (used in the implementation of |
@aepsil0n do you see a usecase where the accumulator is a costly object to clone, or should that be avoided anyways? |
First of all, thanks for looking into this @Darkstalker. I would definitely accept your commit as a pull request. It would be nice to add a minimal test case along the lines of your example to avoid future regressions. The implementation of fold is purely semantic, I have not put any effort to optimize it. That goes for a large part of the functionality. In this particular case my prime suspect would be this line, which would be hard to get rid of. But I'd have to debug this to know for sure. It is certainly necessary to clone once at the end for sampling. The rest might be avoidable in theory. As it is, carboxyl is not provide a zero-cost abstraction for event handling. Reference counting, cloning, dynamic dispatch, etc. are still an issue. I am just not sure, how easy this is to fix without a complete rewrite. @Moredread you are right to some extent. There is something to be said about data structures. Functional programming in the style promoted by this library works best with cheaply clonable purely functional data structures (see Okazaki, 1996). However, it would be nice not to be wasteful. ;) |
made the pull request, but couldn't figure out a reliable way to test it |
fine by me for now… I'll leave this issue open nonetheless, also because there is more to it. |
Did some research about this, and I think I found a solution: passing the value around as https://play.rust-lang.org/?gist=7eee873a19bdbf32122843f9e0d4f133&version=stable&backtrace=0 |
Interesting… this might take some work to update the code accordingly. |
Made a repository with all my work here: https://github.com/darkstalker/frappe |
Tried to implement something that accumulates all the stream values into a
Vec
usingStream::fold
, but found that it clones the accumulator values multiple times during it's operation. Example code:output:
Don't know if I'm using it wrong, but this seems pretty inefficient. A fold operation shouldn't require cloning the accumulator.
The text was updated successfully, but these errors were encountered: