• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Issues with Scala built on JVM

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
author
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

May be this will help you..

First Class Function Scala
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic