pavelpavlov/scala — comment on commit bdf2c627aba4d3e8b5105df9ac1e3f02078bc6fc
File:  line 0
By pavelpavlov:

> My solution has the cost of a synchronized in the construction of the partial function, but the apply is optimal in the sense that it there is no overhead if the original partial function is invoked (as opposed to the orElse argument).
Plus synchronized at every access to APF.fallBack.
So if you have `f = f1 orElse f2 ... orElse fn` then `f1.apply` will be called without overheads whereas for any other `i` `fi.apply` will be preceded by synchronized block.

> Your solution makes the apply go through one forwarder per orElse.
Of course. Note that all orElse chain is flattened during construction so in `f = f1 orElse f2 ... orElse fn` call to `f1.apply` will go through only one forwarder.

As regards to performance, what bothers me more is that both solutions (yours and mine) kills the possibilities of PF specialization (at least return type specialization). I wonder if this can be a problem in future.