On Tuesday, October 9, 2012 9:37:20 AM UTC-4, tbc++ wrote:
>
> >> Polyfns are exactly as fast as protocol functions (I am using the same
> >> caching and dispatch code), but they do not generate a Java interface,
> >> and they are slightly simpler to define.
>
> So I guess I have to ask the question again...what is the true use case of 
> polyfns? Are they faster than multimethods?
>

Dramatically faster than multimethods, just like non-interface based 
protocol dispatch. It is the same code.
 

> If I can get a dramatic speed up by using interfaces, why would I throw 
> that away?
>

Sorry, I should have said that polyfns are exactly as fast as non-interface 
protocol dispatch. As with everything, it's all about tradeoffs. I don't 
recall that I said everyone should be replacing their uses of protocols 
with polyfns, so I don't know why I'm supposed to convince you to do so. I 
think it is useful to have fast polymorphic dispatch separate from class 
generation, and useful as an orthogonal building block with granularity at 
the function level. If you're interested in pure performance, then feel 
free to use protocols. There are downsides to that approach, too. I think 
maybe polyfns might be fast enough for most use cases, but I have some 
ideas for improving performance, too.

I've been experimenting with some Java 7 features. I have a stashed version 
of polyfns that use java.lang.ClassValue as a cache for implementation fns 
instead of a clojure.lang.MethodImplCache. The performance is pretty good, 
and the implementation is simpler.

I'm wondering what kind of performance I could eek out by having a 
ClassValue cache that caches MethodHandles to the implementations instead 
of the IFns themselves. Obviously Clojure isn't emitting invokedynamic call 
sites, but I wonder whether the JVM could inline through that kind of a 
call chain.


Cheers,
Paul

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to