Live data from Hacker News

Clojure 1.3 First Impression (It's Fast)

learningclojure.com

1–10 of 26 posts

Re: Clojure 1.3 First Impression (It's Fast)

#3

Last time I tried Scala, it blew Clojure out of the water for speed on the program I translated. I assume that Java did too. I think that's probably not true any more. Anyway, pretty fractal tree program in lisp!

You're still going to find Scala to be significantly faster on arbitrary code. It's great that there are ways to speed up key functions in Clojure now though.

Re: Clojure 1.3 First Impression (It's Fast)

#4
post #3

Last time I tried Scala, it blew Clojure out of the water for speed on the program I translated. I assume that Java did too. I think that's probably not true any more. Anyway, pretty fractal tree program in lisp!

You're still going to find Scala to be significantly faster on arbitrary code. It's great that there are ways to speed up key functions in Clojure now though.

Backed up by what evidence? And by arbitrary code do you mean code that embraces mutability?

Re: Clojure 1.3 First Impression (It's Fast)

#5
post #3

Earlier quoted context omitted.

You're still going to find Scala to be significantly faster on arbitrary code. It's great that there are ways to speed up key functions in Clojure now though.

Backed up by what evidence? And by arbitrary code do you mean code that embraces mutability?

Scala effectively has these kinds of type declarations on every function. This article itself proves the point. Take out the :static and type decls and see.

Re: Clojure 1.3 First Impression (It's Fast)

#7

As someone familiar with Java/Scala but not Clojure, what exactly do those type hints do? Just prevent it from autoboxing the primitives? Avoid excessive reflection? Can this be done for other types or just int/long/float/etc?

It avoids reflection, and instanceof checks.

Re: Clojure 1.3 First Impression (It's Fast)

#8
post #5

Earlier quoted context omitted.

Backed up by what evidence? And by arbitrary code do you mean code that embraces mutability?

Scala effectively has these kinds of type declarations on every function. This article itself proves the point. Take out the :static and type decls and see.

Idiomatic Clojure tends to use Clojure's persistent data structures - you don't often create custom types, all of the core functions on those data structures are already pretty much as fast as possible. No need for ^:static or type decls.

The article also doesn't get into deftype/defrecord/protocols. In those cases you always get the fastest path of the platform. Again you can build things that have the same perf of the core data structures w/o resorting to ^:static or type decls.

So what exactly do you mean again by arbitrary code? Perhaps you meant numeric code - there ^:static and type decls help plenty. Perhaps you mean Java interop? Again sure.

Personally I think Clojure is really taking the dynamic, generic, and fast thing to a whole new level, w/o type-hinting of any kind.

EDIT: This isn't too say Clojure performance can't continue to improve. Scala's ability to use Java arrays of primitives in higher order operations is something I really, really want to see (and the the above is a big chunk of the work in that direction)

Re: Clojure 1.3 First Impression (It's Fast)

#9

As someone familiar with Java/Scala but not Clojure, what exactly do those type hints do? Just prevent it from autoboxing the primitives? Avoid excessive reflection? Can this be done for other types or just int/long/float/etc?

type-hinting Java objects to avoid reflection has been possible for some time now. What wasn't possible was for fns to take or return primitives w/o boxing. ^:static lets you do that. ^:static also allows the JVM to apply the most aggressive optimizations to your code - ^:static tells the JVM the code won't change - so callers of ^:static fns won't get the latest version if you redef them. The benefit being that with numeric code you'll often see an order of magnitude performance jump.

So a general strategy is to write your code as you normally would - def'ing redef'ing fns at will. Then when it works - declare the critical paths ^:static, and adding primitive type hints ^long, ^double if the code is numeric.

Re: Clojure 1.3 First Impression (It's Fast)

#10
post #5

Earlier quoted context omitted.

Backed up by what evidence? And by arbitrary code do you mean code that embraces mutability?

Scala effectively has these kinds of type declarations on every function. This article itself proves the point. Take out the :static and type decls and see.

Of corse scala is fast with stuff like that because its typed. But should we talk about all the stuff you can't do because you have types all the time?

I think clojure is getting really close to a dynamic language that can get down to the speed of a static language if you need it.

Post reply on HN