On 3/2/14, 7:06 PM, Mikera wrote:
Some perspectives (as someone who has been tuning this stuff a lot,
from a core.matrix standpoint in particular)
On Saturday, 1 March 2014 13:02:26 UTC+8, bob wrote:
Hi,
Can I ask a newbie question about clojure performance?
What make clojure performance slow than java?, it seems clojure
has the 1/4 performance compared to java in general, according to
tests, some cases it might be 1/10. the reasons I can think out are
- the byte code is not efficient sometimes
- the byte code might not enjoy the jvm optimization
Sometimes a problem, though Clojure is not too bad at bytecode
generation and the JIT will do most of the obvious optimisations for you.
- the reflection
This is extremely bad for performance, but luckily it is easy to avoid:
- Always use *warn-on-reflection*
- Eliminate every single reflection warning with type hints
- the immutable data structure
This is often a performance *advantage*, especially when you start
dealing with concurrency and data-driven snapshot.
In the few cases where it is a problem, you can always drop back to
using mutable Java data structures or arrays - so this isn't ever
really an issue.
- the abstract interface design
This doesn't actually cost that much. Interfaces on the JVM are
extremely fast and very well optimised. In many cases, JIT
optimisations make them just as fast as a static method call.
The abstract interface like seq offers its power, but it is easy
to drop in the performance trap.
ISeq itself isn't too bad (it's just an interface, as above), but some
of the implementations are a bit expensive.
Lazy seqs for example are not so fast... and often you don't need the
laziness. However most clojure.core functions produce lazy seqs by
default.
I wrote an "eager-map" replacement for "map" in my clojure-utils
library to get around this problem
Is this any different than core's mapv fn? mapv uses transient vectors
and reduce to eagerly map into a vector.
-Ben
--
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
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.