On Tue, Feb 15, 2011 at 10:02 AM, Marko Topolnik <marko.topol...@gmail.com> wrote: >> > Is really any call that isn't inlined that expensive? >> >> Yes, unfortunately. You saw the numbers. :) > > If you mean the earlier thread about the Euler problem, I see that the > diagonal-sum-3 drastically outperforms diagonal-sum-2 by eliminating > HOFs and working with unchecked primitive ops. Eliminating the use of > HOFs mainly boils down to eliminating lazy-seqs, which bring both > memory and cpu overheads. But if all I have to pay for is a simple > function call (the function being referenced by a local), it may not > be much of a problem, especially on HotSpot, which will probably be > able to inline that code anyway. Of course, if those function calls > introduce boxing that otherwise wouldn't happen, that's a clear > performance issue. Am I wrong about this?
No. The actual function call is no more expensive than an interface method call in Java; but the boxing of numerical arguments causes a performance hit that HotSpot can't for some reason seem to JIT away to nothing. Clojure 1.3 intends to address this, to some extent. HOFs and lazy seqs add a bit more expense. Try deliberately throwing an exception in lazy-seq and then (first (map this (map that ... (my-exception-throwing-lazy-seq)))) and see how deep the stack trace nests; the method call overheads do add up when there's many of them! >> Oh, and we'll finally be able to call functions with long and double >> primitive args and not just boxed numbers. :) > > I think this is the one related to "Unless you're using 1.3 or > later..." since it allows for sub-functions that don't break the > primitive chain. Yes. >> I don't think the loop in diagonal-sum-3 (see other thread) is really >> "non-idiomatic", /for code that needs speed/. > > But generally, it is even better when your clean-looking code performs > well -- and if the compiler can achieve that, it obsoletes any > specialized idioms for optimal code. No argument there. -- 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