Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issues with Scala built on JVM

 
munthajeeb akbar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly the introduction in the book FP in scala focusing on FP and using scala as an example is excellent and very helpful since the power of scala is in understanding FP well. - Thanks a lot for writing this book !!!
my questions on scala:-
1) does scala have any performance improvement compared to Java ?
2) if the underling JVM changes how will scala survive ?
3) is there any limitations on scala since it is build on top of JVM ?
 
Runar Bjarnason
author
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does scala have any performance improvement compared to Java?


No. Scala code is exactly as fast or slow as the equivalent Java code.

if the underling JVM changes how will scala survive?


If the JVM changes, I suspect Scala will change too.

is there any limitations on scala since it is build on top of JVM ?


There are some limitations that come with the JVM, yes. For instance, there is no JVM byte code for tail calls. Tail call elimination is particularly important in FP, so we have to resort to techniques like trampolining (covered in chapter 13 of the book).
 
Joe Harry
Ranch Hand
Posts: 10123
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a rather strange question. In Scala each function ends up as a class file after compilation. If I have say 100 functions in a Scala class, I end up having roughly 100+ classes and loading all these functions as classes in the memory during run time would cause performance issues? Can you please throw some light on that?
 
Runar Bjarnason
author
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Harry, that is another historical limitation of the JVM. Until Java 7 there was no way to get an unboxed method handle in the compiler, so in order to get first-class functions Scala and others resorted to anonymous classes with a single method (Function1 and friends). This definitely has a memory overhead.

Note that Scala methods are still just ordinary methods. This limitation is specific to first-class functions, or closures.

As of Java 7, the JVM provides method handles first-class in the byte code. So hopefully Scala will take advantage of these at some point.
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

May be this will help you..

First Class Function Scala
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic