6 ms·
Clojure++ (notes from Rich Hickey talk)
- herdrick 16y ago"... most numeric functions in Clojure, will no longer auto-promote values to Big numbers..." Oh no! Clojure is choosing the route of premature opt. What a terrible shame.
- peregrine 16y agoThis is only true if you use the annotations, at least that is my understanding.
- herdrick 16y agoReally? That'd be fantastic. Did I misunderstand this?
- peregrine 16y agoYes the annotations are purely optional.
- herdrick 16y agoRight, but the initial quote seemed to say that promoting to BigNums would no longer be automatic. But I may have misunderstood.
- richhickey 16y agoCorrect, promotion will no longer be automatic because the semantics of primitive and auto-promoting arithmetic can't be unified (on the JVM with no fixnums, the return types are disjoint). However, missing from the blog post and discussion here is the fact that, should there be overflow, an exception will be thrown. We are not adopting the silent error strategy of C/Java etc.
- prospero 16y agoI was at the talk in question. Some more context: Bignums "contaminate" surrounding operations. Adding a long and a bignum yields a bignum. Seeding an equation with a single bignum (42N is a bignum representation of 42) will prevent overflow. No one has come forward with a single real-world scenario where they're using bignums in Clojure. Choosing a default that is only theoretically useful rather than a 10x performance improvement seems a bit silly. In any situation where the compiler cannot be sure you're using primitives everywhere, it will emit non-overflowing bytecode. By my measure, there's nothing premature about this optimization. In Rich Hickey's words, Clojure is a replacement for Java, not Ruby. Giving up Java-like performance makes the language quantitatively less useful.
- herdrick 16y agoThat Clojure's target is to replace slow old Ruby (actually that never happens, rather a successful language gains dominance in some niche and spreads from there) is only more evidence that it isn't worth breaking the abstraction called "numbers" to get merely an order of magnitude better performance. Seriously, I almost can't believe this is still an open issue in 2010. And Rich Hickey, who has designed such a great language otherwise, is on the wrong side of it? I'm boggled. EDIT: If peregrine's comment is right, then we're arguing about something that isn't happening. I hope so.
- swannodette 16y agoPremature? No people have been complaining (or just getting very confused) about Clojure's numeric performance without oodles of invasive type-hinting for two years now. More importantly with these changes it's now possible to reimplement Clojure's core datastructures in Clojure without sacrificing performance. The majority of people who care about BigInts are solving Project Euler problems, not writing Clojure libraries or deploying apps into production.
- herdrick 16y ago2^63 numbers ought to be enough for anyone, huh?
- silentbicycle 16y agoThe situations that deal with numbers that large are usually a bit nuanced. (i.e., "it's 1 in 2^63 of the time that I need bignums for day-to-day programming"). I agree that losing accuracy needlessly sucks (and I've been burned by floating-point), but 64 bit ints are usually good enough. I'm thirsty for counterexamples.
- rbanffy 16y agoshouldn't it be called (++ clojure) or something like it?
- djacobs 16y agoOr (inc clojure) perhaps? Isn't (++) an abomination in functional programming with immutable state?
- adbge 16y ago++ isn't defined in Clojure, and in Haskell ++ is used to concatenate lists. Using (inc) isn't considered an abomination, though.
- lmkg 16y ago(swap! clojure inc) is acceptable and a more literal translation, although refactoring your code to use (inc clojure) is usually more idiomatic. See also, ADD 1 TO COBOL GIVING COBOL.
- silentbicycle 16y ago"(inc clojure)". which is probably really good marketing. (About e.g. "succ ml", I'm not sure.)
- djacobs 16y agoWell, I agree with you that isn't fantastic marketing. But neither is using a mutator function name to describe a talk on a functional language. Rich Hickey loves to rail against nonsensical constructs/concepts like @date.day = 3, and I'm guessing he is very against the (++) method, as well. (How can you tell one number to become another number?)
- SeanLuke 16y agoHmmm, Kawa's been doing this for better part of a decade. I tried this in kawa: (def (fib n :: <long>) :: <long> (if (<= n 1) 1 (+ (fib (- n 1)) (fib (- n 2)) Almost identical speed results to Rich's "improved" version.
- fogus 16y agoRich is not trying to improve over Kawa. He's trying to improve over previous versions of Clojure.
- nickik 16y agoWe are in Clojure Alpha 1.3 v1 and allready the same speed. The did it for a dacade and rich does it for a couple months and you bash him? We arn't the kawa guys faster after a decade. Clojure is faster in other stoff like interop witch is really importend on the JVM. Can Kawa write down-to-java speed types?
- SeanLuke 16y ago> We arn't the kawa guys faster after a decade. Kawa guy. Kawa was written by a single person, Per Bother, in his spare time. Clojure has a massively larger mindshare and collection of coders behind it. Ask yourself: why has Clojure been so slow for so long? > Clojure is faster in other stoff like interop witch is really importend on the JVM. Actually in my experience this is where Clojure is very slow indeed. If Clojure has to convert everything to Refs, it gets extremely slow (in our tests on my simulation system, up to 1000x slower than Kawa. I am not making up that number.). > Can Kawa write down-to-java speed types? Absolutely.
- SeanLuke 16y ago> We arn't the kawa guys faster after a decade. Kawa guy. Kawa was written by a single person, Per Bother, in his spare time. Clojure has a massively larger mindshare and collection of coders behind it. Ask yourself: why has Clojure been so slow for so long? > Clojure is faster in other stoff like interop witch is really importend on the JVM. Actually in my experience this is where Clojure is very slow indeed. If Clojure has to convert everything to Refs, it gets extremely slow (in our tests on my simulation system, up to 1000x slower than Kawa. I am not making up that number.). > Can Kawa write down-to-java speed types? Absolutely.
- d0m 16y agoBut: (defn ^:static fib ^long [^long n]) is really not sexy.
- ataggart 16y agoThe performance alternative was dipping into java. It's sexy enough.
- puredanger 16y agoIsn't "sexy enough" Clojure's motto?
- nickik 16y agoits better then optimicing CL. But you write you will only to that if you really need the bare metal performance. I want do that in day to day code. The ^long thing is pretty cool bettr then : <long> or something. Its nice that it is just metadata.
- ataggart 16y agoThe changes are pretty substantial when you need them. I wrote a clojure implementation of Base64 that's faster than apache's commons-codec. In 1.2 it was about 5x slower.
- nickik 16y agoIn what version of clojure could you write it with the same speed?
- jules 16y agoCouldn't you speed up loops without annotations by compiling two versions: one that uses longs and one that uses bignums. You start in the loop that uses longs and before an operation that can overflow you check whether it overflows and if so you jump to the loop that uses bignums. This way you only suffer a few extra checks which is a lot cheaper than boxed numbers.
- c00p3r 16y agoWe don't need Scheme++ to implement .... (c) Brian Harvey, a famous CS61A teacher. ^_^