Live data from Hacker News

Why is Clojure so slow?

martinsprogrammingblog.blogspot.de

41–50 of 97 posts

Re: Why is Clojure so slow?

#41
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...

Those benchmarks are fairly useless, because it doesn't compare idiomatic usage of those languages, but rather the capability of those languages to drop to low-level primitives and libraries.

I did an experiment once, testing out a simple web-service on the JVM and Scala (with Scalatra) yields the same performance as Java (with Jax-RS), while Clojure (with Noir) is only 2x to 3x as slow and JRuby (Sinatra) is only 4x-5x as slow as Java.

Re: Why is Clojure so slow?

#42
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...

This is the same benchmark that is used in the OP. So if you object to the characterization of Ruby/Python/PHP vs Clojure, you can make the same objection regarding the characterization of Clojure vs C.

Re: Why is Clojure so slow?

#43
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 m…

Tax is the wrong word... It's not the case that the Clojure (the language, the developers, etc) benefits from slow startup. Fine is probably more accurate.

Re: Why is Clojure so slow?

#44

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 serv…

For dynamic languages such as Clojure or JRuby, a "JIT cache" would do no good.

Re: Why is Clojure so slow?

#45
post #43

Earlier quoted context omitted.

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 m…

Tax is the wrong word... It's not the case that the Clojure (the language, the developers, etc) benefits from slow startup. Fine is probably more accurate.

"Performance" is never the end-goal, but rather a coin you can trade for other things, like convenience, lower latency, fewer hardware resources, getting results faster, scalability, etc... basically anything that makes you or your clients happier. When people say they want performance, they actually mean they'd like the flexibility to gain something else by paying with performance.

That's why I used "tax" which I think is very suitable.

Re: Why is Clojure so slow?

#46
post #8

Don't compare Clojure to C, comparing it to Python or Ruby makes more sense because they're all high-level dynamic languages. Sure Clojure runs on the compiling JVM but that doesn't put it into another category; you can also JIT compile Python in a few ways. If we can make working websites and even games in Python, we can make them in Clojure too. What kills Clojure for small scripts and not-long-running applications…

What kills Clojure for small scripts and not-long-running applications is the startup time and that can mostly be attributed to JVM

Did you not read the article? Quote: "What we can see is that Java itself accounts for 0.35s of the startup time, but unfortunately Clojure adds another second(!) on top of that."

So no, it can not be mostly attributed to JVM.

Also, JVM in a low death spiral? What gives you that impression, the growing number of languages that target it? The fact that new versions continue to receive improvements, such as better support for dynamic languages in v. 7?

Re: Why is Clojure so slow?

#47
post #35
post #31

Earlier quoted context omitted.

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.

100K is a lot of code for a Hello World, so don't use ClojureScript to write Hello World apps. The cool part is that building a largish app will not necessarily grow the output JS.

Re: Why is Clojure so slow?

#48
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.

Unfortunately for Oracle, Java represents a genie that's out of the metaphorical bottle. They have the privilege to be its benevolent steward, however if they keep pushing for control in the face of its community, they'll lose whatever control they have left.

The recent lawsuit kind of highlights that. Google is riding on years of development and refinement of Java IDEs and on mountains of available open-source libraries. They jump-started an Android community from zero by building an alternative VM for targeting Java source code, while giving the finger to Sun/Oracle and their licensing.

And I don't think they are so stupid as to not realize this.

Re: Why is Clojure so slow?

#49

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 serv…

For dynamic languages such as Clojure or JRuby, a "JIT cache" would do no good.

Don't assume that an interactive language is necessarily interpreted. Clojure compiles to JVM bytecodes: http://clojure.org/compilation

Re: Why is Clojure so slow?

#50
post #8

Don't compare Clojure to C, comparing it to Python or Ruby makes more sense because they're all high-level dynamic languages. Sure Clojure runs on the compiling JVM but that doesn't put it into another category; you can also JIT compile Python in a few ways. If we can make working websites and even games in Python, we can make them in Clojure too. What kills Clojure for small scripts and not-long-running applications…

Don't compare Clojure to C, comparing it to Python or Ruby makes more sense because they're all high-level dynamic languages For me the more obvious comparison would be with other Lisps. Which, back in the dim past when I was using 'em, were often damn fast.

If you're looking for a fast JVM-based Lisp the obvious choice would be Kawa Scheme: http://per.bothner.com/blog/2010/Kawa-in-shootout/

But as fogus said, speed is only one piece of the puzzle. http://news.ycombinator.com/item?id=4223562

Post reply on HN