more-executors
more-executors copied to clipboard
Collapse f_and/f_or for better performance?
Consider the following:
f = f_and(f1, f2)
f = f_and(f, something)
f = f_and(f, other)
f = f_and(f, foo)
f = f_and(f, bar)
# ...
That will create various chained objects (AndOperation under the hood). In practice code might be written in a way such that the chain ends up thousands of items deep.
Consider if it's practical & useful to collapse the objects in this case. e.g. is it possible to arrange it so that, in f_and(a, f_and(b, c))
, the outermost f_and could generate an object equally as efficient as f_and(a, b, c) ?
I looked into it and don't think there's much that can be done.
- In the case where futures have already completed by the time f_and is called, 100,000 chained calls already seem to be about as efficient as a single call with 100,000 futures.
- In the case where futures haven't completed, there doesn't seem to be any reasonable way to avoid needing O(N) frames on the stack where N is the number of futures.
Reopened after changing my mind about it. I think it should be possible to do something about this after all.