4 ms·
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.
by edifice 16y ago
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.
- swannodette 16y agoBacked up by what evidence? And by arbitrary code do you mean code that embraces mutability?
- edifice 16y agoScala 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.
- swannodette 16y agoIdiomatic 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)
- jules 16y agoIt's strange that you mention Clojure's persistent data structures as an advantage for performance. They have many advantages but performance isn't one of them.
- swannodette 16y agoI'm curious how you come to this conclusion? Programs in any language will often be designed around immutability in order to improve code maintainability. Without fast persistent data structures this will most certainly decrease the performance of your otherwise elegant design due to considerable amounts of copying.
- lukev 16y agoIf you're going for raw speed you should use mutable data structures. Sadly, that's just the way it is - you can update a mutable data structure in a couple of instructions by swapping out a pointer, while "updating" an immutable/persistent object is inherently more work at the machine level. Clojure is awesome because it provides immutable persistent structures that are well onto the good side of "good enough", not because it's the fastest thing possible. Java itself is far from the fastest thing possible, and the speed of Java is itself a strict upper bound on Clojure's speed.
- swannodette 16y agoSure, but of course if you want raw speed you would write assembly. Most people move up the food chain to C to get some basic level of correctness. I think the history of production oriented PLs has revolved around balancing correctness/performance. And it's always a question of diminishing return (I've written enough C/C++/Objective-C++ to know this). Every sizeable application I've written in a lower level language eventually approaches some kind of wacky manual memory management scheme to preserve performance w/o sacrificing correctness. I think Clojure's solution is a step in the right direction. But no, if I was writing a real-time system with extremely limited memory constraints I would not write in the Clojure. But I don't think that's what this thread is about.
- nickik 16y agoOf 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.
- johnaspden 16y agoYes, let's. You first!