News for hackers. Stuff that matters.
Re:Is Scala really Faster than Java? by gaius on Tuesday June 21, 2011 @08:35AM (#2678465)
I can't find the link right now, but there was a blog post from one of the F# team at MS, saying the CLR team couldn't believe the rate at which he was allocating and deallocating memory, and some tuning needed to be done on the CLR to support F# performance. If you are working with recursion and folding rather than for-loops, under the covers you will be doing one malloc() per iteration, you will definitely need some sort of clever memory management rather than relying on just the OS's implementation.
Re:Is Scala really Faster than Java? by Peaker on Tuesday June 21, 2011 @08:51AM (#2678519)
Why would there be one malloc() per iteration if you have tail-recursion?

Also, isn't malloc() a misnomer for stack allocations?

Re:Is Scala really Faster than Java? by jules on Tuesday June 21, 2011 @09:10AM (#2678585)
Tail recursion has nothing to do with garbage collection in F#. You're going to have one allocation per iteration if you do e.g. a map over a list. In an imperative language you'd probably mutate the collection in place.
Re:Is Scala really Faster than Java? by eru on Tuesday June 21, 2011 @09:43AM (#2678699)
Unless, and I guess that's what ColinWright alluded to, you have extensive stream fusion that will get rid of intermediate data structures.
Re:Is Scala really Faster than Java? by jules on Tuesday June 21, 2011 @10:05AM (#2678784)
That's something else entirely compared to tail call optimization, but yes some functional languages (e.g. Haskell) do this. I don't think F# does stream fusion though.
Re:Is Scala really Faster than Java? by loup-vaillant on Tuesday June 21, 2011 @10:25AM (#2678849)
I'd be surprised if the current implementation of F# didn't do anything of this sort. But as a language, I understand fusion is more difficult in ML than in Haskell: that's because ML is strict and non pure. Therefore, some of the assumptions you could do in a non-strict, pure language don't hold, and it may not be unconditionally true that

  ∀f, ∀g, map g ∘ map f == map (f ∘ g)
because f or g could perform some side effect, or fail to terminate. (My example may be bogus, but I'm sure we can find some real one.)
Re:Is Scala really Faster than Java? by eru on Tuesday June 21, 2011 @11:37AM (#2679178)
Failure to terminate exists in Haskell, too.
Re:Is Scala really Faster than Java? by loup-vaillant on Tuesday June 21, 2011 @12:04PM (#2679291)
Sure, but the order of evaluation do change something. For instance, infinite lists won't ever terminate, but taking the first 42 elements of an infinite list will terminate in Haskell, and not in ML. If you want to fuse the whole thing, it won't change the Haskell program, but it may change the ML one, by making it terminate an return the correct result!

That's not an optimization any more, that's a language feature.

Re:Is Scala really Faster than Java? by eru on Tuesday June 21, 2011 @03:25PM (#2680032)
Yes. Though the situation is only that rosy in Haskell under some circumstances. It's easy to get space leaks that make your program use O(run-time) memory, if you are not careful with the laziness.
Re:Is Scala really Faster than Java? by loup-vaillant on Tuesday June 21, 2011 @05:38PM (#2680540)
Agreed. My only point is that automatic fusion (stream, shortcut, and even inlining in general) "works" more often in a pure and lazy setting.
Re:Is Scala really Faster than Java? by gaius on Tuesday June 21, 2011 @09:46AM (#2678710)
In this case, I believe not:

http://java.sun.com/docs/books/jvms/second_edition/html/Over...

You would not be using the stack for this.