Skip to content
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

Allow non-Clone types #26

Closed
milibopp opened this issue Jan 30, 2015 · 2 comments
Closed

Allow non-Clone types #26

milibopp opened this issue Jan 30, 2015 · 2 comments

Comments

@milibopp
Copy link
Owner

Currently all values passed into a sink to be processed by the event graph, have to satisfy quite a number of trait bounds, namely Send + Sync + Clone. Passing an object down the event graph is achieved by cloning. This is not optimal for larger heap-allocated types, say a Vec or a HashMap, where cloning is expensive. This can be alleviated by wrapping those types in an Arc, so that only references will be sent down the event graph. However, this is a bit clumsy to work with.

Using Arc

As an alternative we could use Arc internally for all values. Functions passed to the primitives would then have to take their arguments by reference and similarly .sample() and .events() would yield references.

On the upside, working with cells and streams would become more ergonomic, as one would not have to think about expensive cloning of each event sent into a stream. It also drops the Clone bound on the type of an event.

The downside is, of course, that this constitutes a bit of an unnecessary overhead for small types. But then again, the library currently uses a lot of atomic ref-counting, vtable dispatch and pointer indirection. One more indirection would likely not be that harmful.

@milibopp milibopp changed the title Internally wrap values into Arc? Internally wrap values in an Arc? Jan 31, 2015
@milibopp
Copy link
Owner Author

milibopp commented Feb 4, 2015

Negative trait bounds would allow the best of both worlds.

@milibopp milibopp changed the title Internally wrap values in an Arc? Allow non-Clone types May 5, 2015
@milibopp
Copy link
Owner Author

milibopp commented May 5, 2015

Having tried this once again, it appears that the internals would have to be much more sophisticated to allow this. It's not clear that this is actually worth it. Thus closing.

@milibopp milibopp closed this as completed May 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant