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

Behaviors are sometimes recomputed unnecessarily #10

Closed
HeinrichApfelmus opened this issue Aug 28, 2011 · 3 comments
Closed

Behaviors are sometimes recomputed unnecessarily #10

HeinrichApfelmus opened this issue Aug 28, 2011 · 3 comments

Comments

@HeinrichApfelmus
Copy link
Owner

One of the "small efficiency problems" I alluded to in the package description is that behaviors are sometimes recomputed unnecessarily.

Example:

let b = bexpensive <*> bin
in (liftA2 (+) b b) <@> e1

The value corresponding to bin will be computed twice. While this doesn't make a difference semantically, it may be expensive.

There is no fundamental reason for this omission, I was just too lazy to implement it. The main reason for that is that I will have to revamp all the internals in a future release anyway. The future release won't happen very soon, though, that's why I'm mentioning the issue here.

By the way, the offending code is the ApplyB case of the following function:

-- compile a behavior
-- FIXME: take care of sharing, caching
compileBehaviorEvaluation :: Behavior Linear a -> Run a
compileBehaviorEvaluation = goB
    where
    goB :: Behavior Linear a -> Run a
    goB (ref, Pure x)            = return x
    goB (ref, ApplyB bf bx)      = goB bf <*> goB bx
    goB (ref, ReadBehavior refb) = readBehaviorRef refb

At the moment, it doesn't include any provisions for observable sharing.


Let me know if this turns out to be a problem for you; I will fix it if there is demand.

@ehird
Copy link

ehird commented Aug 29, 2011

Looks like your example has an error, unless you intended to never reference b.

@HeinrichApfelmus
Copy link
Owner Author

Oops, thanks. Fixed.

@ghost ghost assigned HeinrichApfelmus Sep 6, 2011
@HeinrichApfelmus
Copy link
Owner Author

The internal changes in reactive-banana-0.5 eliminate this issue.

So, unless I messed up observable sharing or something, this problem is gone for good. It's time to close, yeah!

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

2 participants