You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
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 aVec
or aHashMap
, where cloning is expensive. This can be alleviated by wrapping those types in anArc
, 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.
The text was updated successfully, but these errors were encountered: