5 ms·
Working with immutable data in Lua is not a good idea if you care about performance. You end up generating a massive number of short-lived objects and Lua is no
by copx 13y ago
Working with immutable data in Lua is not a good idea if you care about performance. You end up generating a massive number of short-lived objects and Lua is not built for that.
Java's advanced generational GC can handle it surprisingly well but of course for decent performance you want a language implementation optimized for working with immutable data (e.g. GHC, Clojure).
- glibgil 13y agoClojure is slower than Java.
- simias 13y agoBut is it slower than the equivalent functional code ported to Java?
- glibgil 13y agoYes, of course it is. Nothing in Clojure is faster than Java, not even functional programming.
- chongli 13y agoNothing in Clojure is faster than Java, not even functional programming. Right, but that's completely ignoring programmer efficiency (or sanity). Trying to do the things that Clojure was designed for in Java is a recipe for pain.
- glibgil 13y agoNo, it works fine. If you are doing FP then things stay well organized no matter the language.
- chongli 13y agoNo, I'm talking about the things which Clojure is really good at. Macros, embedded domain-specific languages etc. Try doing something like core.logic in pure Java.
- glibgil 13y agocore.logic can be done cleanly in Java, no problem. For example, here is an FP library in pure Java. Nice clean code. Easy to use. https://code.google.com/p/totallylazy/ https://code.google.com/p/totallylazy/
- Tuna-Fish 13y agoIf you are using Clojure's built-in types to do fp vs Java's built-in types, Clojure will win by an absurd margin.
- glibgil 13y agoYou don't need Java's built-in types when you are doing FP in Java. In fact, it is not really FP if you do. Java FP is faster than Clojure in everything.
- simias 13y agoUh, I didn't expect that. How come? Does it mean that writing a Clojure-to-Java transpiler would yield better results than using the "native" Clojure implementation? It seems backwards to me that an implementation designed specifically for functional programming fails to beat the more "generic" (or arguably OOP-oriented) language on its own turf.
- chii 13y ago> Does it mean that writing a Clojure-to-Java transpiler would yield better results than using the "native" Clojure implementation? yea, it does sound weird, because if a closure-to-java compiler yields better results, then why not just use that as the closure compiler? I agree that hand writing a piece of code in java that did the exact same thing as a piece of closure code would be faster in java than closure, because the programmer could make shortcuts where he knows he could.
- russellsprouts 13y agoFor relatively simple data, like small structs, you can use memoization to achieve immutability. Programming in Lua has a section on it. http://www.lua.org/pil/17.1.html http://www.lua.org/pil/17.1.html
- DanWaterworth 13y agoSee also: http://wiki.luajit.org/New-Garbage-Collector http://wiki.luajit.org/New-Garbage-Collector
- copx 13y agoNot there yet, not even close. Mike Pall announced his proposal for a new GC a long time ago and thus far no sponsor has shown up. I doubt there is enough interest. This is a major project (i.e. non-trivial amount of sponsor money needed) and Lua users (including myself) seem to be happy with Lua's simple, incremental GC. It does work well for typical Lua use cases.
- justincormack 13y agoI think that its more about there being other things people want sooner. He seems to have a lot of sponsorship and has had open ended offers.
- kzrdude 13y agoThat article is very well written, thanks for the link!
- asdf1234 13y agoClojure performs well because of the JVM. Other than the immutable data structures that it includes, which are written in Java, it isn't optimized particularly heavily for dealing with immutable data.
- copx 13y agoI was thinking of Clojure's persistent data structures when I said optimized for immutable data. There is a world of difference between those and creating a new object every time you want to change something.
- maccard 13y agoSurely you can disable the garbage collector for particular segments of code?