On May 10, 10:34 am, Christophe Grand <
christo...@cgrand.net> wrote:
> Hi all,
>
> If I understand correctly a protocol-fn's fastest path is when the class of
> 1st arg is the same as the one of the previous invocation, it makes sense
> for tight loops where data tend to be homogeneous.
> What bothers me is when two (or more) concurrent loops process each one with
> a different datatype (and it may happen for low-level fns such as conj):
> each thread is going to reset the .mre field in MethodImplCache to their
> favorite value, effectively degrading performance.
>
> Is this a real problem? (if no please disregard next questions)
No more so than any other caching strategy.
> Can this be adressed with, one day, invokedynamic support?
No, same issues there. Essentially, the usual strategy for inline
caches is that, should they be determined to be heavily polymorphic
(megamorphic), they back out of caching altogether and use the slow
path always. I think what is happening here is better, as the cost of
this (in this case, ineffective) caching is negligible compared to the
overhead of detecting the polymorphism and bailing out of caching.
> Does the .mre field need to be volatile (since it points to an immutable
> Entry object) and could this change (making .mre non-volatile) alleviate
> this problem?
>
It was non-volatile before, and may return to that, but that was
turned off in a general sweep of other (now resolved) issues. Note
that this is not really a concurrency thing at all. You might see it
just from single threaded use over a heterogeneous collection.
I think what is in question is the presumption of uniform performance.
That is not to be expected. The fastest support is inline definition,
as then you have an interface hooked into the class of the target
itself. (Note that even an instanceof check can vary in perf due to
the complexity of the class hierarchies involved). Next fastest is
(temporally) homogeneous use, optimized by the caching. Finally,
heterogenous use, not helped by the caching, the perf of which is
dominated by the lookup, not the caching of its result. This scales
gracefully and, even in the latter case, is quite fast.
Rich