-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Bad performance of _Reader created by 'then' method #14
Comments
Hey, thanks for bringing this to my attention. Especially since it's something I should have noticed myself ages ago. Safe to say that exponential complexity is definitely not the intended behaviour. So I've had a quick look at this and, unfortunately, won't have time to really dig into it until at least the weekend. But the good news is your solution appears to work for Reader. The bad news is other monad have similar constructions and therefore suffer the same complexity problem. And a similar solution doesn't appear to work for those. State in particular has even bigger problems which I'll need to figure out. Hopefully I can find a general solution to fix the problem across the board. I'll keep you posted. In the meantime, using map and bind directly instead of deferring to then should avoid performance problems in most cases. |
So, I've fixed the exponential complexity problem in every monad where it was a problem and also fixed Promise which, it turns out, was really broken. Thanks again for bringing this to my attention. |
Alright, all fixed. New version is 2.3.5 available here and on PyPi. |
I do not know if this is a bug or correct behaviour. This is what I observed:
The result of execution is:
I expected to see this:
Implementation of _bind_or_map is responsible for this:
First _bind is used to compute the result. Bind do mapping and fails on actual binding.
Then everything is computed again by _map. This has exponential complexity.
I believe fix could do 'map' then try to 'bind':
The text was updated successfully, but these errors were encountered: