Live data from Hacker News

Why is Clojure so slow?

martinsprogrammingblog.blogspot.de

31–40 of 97 posts

Re: Why is Clojure so slow?

#31
post #30

"When using the ClojureScript compiler on a hello word example with advanced optimisation, we end up with some 100kb of Javascript. [...] The Google Closure compiler certainly helps here by removing lots of unused code, and the resulting Javascript file is indeed free from all docstrings etc." So does the ClojureScript compiler basically just embed a Clojure interpreter in every file? I'd be interested to see the cod…

No, ClojureScript does not interpret ClojureScript at runtime. The Clojure forms are compiled down to JavaScript directly. More info at http://blog.fogus.me/2011/07/21/compiling-clojure-to-javascr...

Re: Why is Clojure so slow?

#32
post #20
post #14

Earlier quoted context omitted.

Maybe the typical JVM bashing. In most enterprises, regardless what we think about the JVM, it is still quite healthy.

For my part, I don't trust Oracle to be a good steward for Java. Who knows - time will tell. It's not all gloom and doom though; Attila Szegedi is at Oracle now, working on Nashorn - something exciting for Java 8.

So he left Twitter. I didn't realize that. Exciting indeed.

Re: Why is Clojure so slow?

#33
post #27
post #21

Clojure has a slow startup time . It is not in itself slow. It's important to get these distinctions right! Some people, unfortunately, form impressions from headlines and in this case it's extremely inaccurate. If you read the article you'll get the truth - there are startup time problems causing issues with using Clojure for command-line programs. That's much less damning overall than "Clojure is slow."

You should have read the entire article: > How fast is Clojure at running your code once it finally has got going? ... Clojure is on average 4x slower than Java and 2x slower than Scala. That's pretty freaking slow.

You can always match the speed of java in critical areas by disabling number boxing, adding type hints, and using the mutable versions of data structures. This is what prismatic did for their ML computation code: http://www.infoq.com/presentations/Why-Prismatic-Goes-Faster...

Re: Why is Clojure so slow?

#34
post #27
post #21

Clojure has a slow startup time . It is not in itself slow. It's important to get these distinctions right! Some people, unfortunately, form impressions from headlines and in this case it's extremely inaccurate. If you read the article you'll get the truth - there are startup time problems causing issues with using Clojure for command-line programs. That's much less damning overall than "Clojure is slow."

You should have read the entire article: > How fast is Clojure at running your code once it finally has got going? ... Clojure is on average 4x slower than Java and 2x slower than Scala. That's pretty freaking slow.

> That's pretty freaking slow.

I suppose in a vacuum it is indeed (assuming the measurements are general), but in my actual use the speed of Clojure has been more than sufficient. People like to view programming language speed as a black and white issue in the context of blog and HN posting, but in many uses runtime and startup speed considerations are only part of the puzzle.

Re: Why is Clojure so slow?

#35
post #31
post #30

"When using the ClojureScript compiler on a hello word example with advanced optimisation, we end up with some 100kb of Javascript. [...] The Google Closure compiler certainly helps here by removing lots of unused code, and the resulting Javascript file is indeed free from all docstrings etc." So does the ClojureScript compiler basically just embed a Clojure interpreter in every file? I'd be interested to see the cod…

No, ClojureScript does not interpret ClojureScript at runtime. The Clojure forms are compiled down to JavaScript directly. More info at http://blog.fogus.me/2011/07/21/compiling-clojure-to-javascr...

I wonder if his figure is simply mistaken, then. Because 100 kilobytes is a heck of a lot of code for a hello world. The compiled representations in your blog post seem far more reasonable.

Re: Why is Clojure so slow?

#36
post #29
post #27

Earlier quoted context omitted.

You should have read the entire article: > How fast is Clojure at running your code once it finally has got going? ... Clojure is on average 4x slower than Java and 2x slower than Scala. That's pretty freaking slow.

And about twice as fast as Erlang, 5x faster than Ruby, Python or PHP and 10x faster than Perl.[1] It's all relative. [1] http://shootout.alioth.debian.org/u64q/which-programming-lan...

On the other hand, those languages do not have a pretension of being fast.

Re: Why is Clojure so slow?

#37
post #6
post #4

If Clojure could dump the Lisp image like SBCL's save-lisp-and-die function, the startup time would be greatly reduced. I wonder if JVM itself can dump its current state and then restore execution. Another approach to the problem would be similar to FastCGI: keep one Clojure server process running and execute scripts on it.

> If Clojure could dump the Lisp image like SBCL's save-lisp-and-die function, the startup time would be greatly reduced. I wonder if JVM itself can dump its current state and then restore execution. It's still hard to understand why aren't Oracle working on something like that. It's not as if they don't care about desktop at all -- JavaFX is going to be part of Java8 and they are even working on a new packaging tool…

"JVM's start-up time and inability to allocate memory when needed (as compared to up-front way it's done now).."

Care to elaborate? Are you saying that the JVM can't malloc()? :)

Re: Why is Clojure so slow?

#38
post #29
post #27

Earlier quoted context omitted.

You should have read the entire article: > How fast is Clojure at running your code once it finally has got going? ... Clojure is on average 4x slower than Java and 2x slower than Scala. That's pretty freaking slow.

And about twice as fast as Erlang, 5x faster than Ruby, Python or PHP and 10x faster than Perl.[1] It's all relative. [1] http://shootout.alioth.debian.org/u64q/which-programming-lan...

While interesting, those benchmarks are only useful if you implement something remotely similar to the actual benchmarks. Just glazing over them, they seem to be "unfairly" targeted at low-level languages.

That said, they are fun to look at. I just had a wtf-moment looking at this:

http://shootout.alioth.debian.org/u32/performance.php?test=n...

~20 seconds vs ~20 minutes??

Re: Why is Clojure so slow?

#39
post #21

Clojure has a slow startup time . It is not in itself slow. It's important to get these distinctions right! Some people, unfortunately, form impressions from headlines and in this case it's extremely inaccurate. If you read the article you'll get the truth - there are startup time problems causing issues with using Clojure for command-line programs. That's much less damning overall than "Clojure is slow."

Slow/fast is a subjective metric, however in case of a language like Clojure you have to pay the price for convenience in the form of a performance tax when compared to Java or Scala.

This may be acceptable, depends on where you're coming from and what you're needs are. For instance if you are coming from Ruby or Python because you want much better performance and you think the JVM is awesome for that, then Clojure may not be a good choice. On the other hand if you want a modern Lisp that's also reasonably fast and that has access to the JVM, then Clojure is a really good choice.

Personally that's why I like Scala, but you know, the best language is whatever makes you happier and more productive.

Re: Why is Clojure so slow?

#40
It's an implementation problem of Java.

I never understood why the JVM folks didn't get along to develop a JIT cache. That means the first time I start a Java program it would run normally slow. But from the second run on it would use the native cache and run immediately fast with native performance. That would eliminate many performance problems of Java.

I know that there already is a solution which uses a Java server to serve the application as client which reduces the startup time but this is not very convenient to use.

The slowness of Clojure is a typical problem of all languages which are based on JVM. Racket Scheme, for instance, which is a Lisp like language but NOT based on JVM, needs just 0.062s to print "Hello World" (compiled) on my system.

Post reply on HN