2

As far as I understand JShell statements are wrapped in synthetic classes when the code snippet is evaluated the first time. This is documented in the JEP-222.

Can I conclude that excluding the first evaluation of the snippet (let's say a method definition and call) that triggers generation of synthetic class, methods and variables, the following calls (for instance calling the same method in a loop) to the same code snippet will perform as fast as normal java code and could even be compiled by the Java compiler at runtime if the snippet becomes "hot"

Naman
  • 27,789
  • 26
  • 218
  • 353
greg
  • 306
  • 1
  • 13
  • Could you explain the question better on the line of *the following calls to the same code snippet*? Maybe some example to look into. – Naman Oct 11 '17 at 14:54
  • I meant for instance defining a method in the snippet and then call it in a loop – greg Oct 11 '17 at 14:57
  • Not very clear on what you're trying to gain from this apart from the performance aspect that might have been reasoned while developing the JShell. On another side what makes you believe otherwise of what your question already is? Why can you *not conclude that ...* (just curious to know)? – Naman Oct 11 '17 at 17:50
  • Actually we are now using MVEL and Groovy expressions that are compiled and then executed millions of times. The overall is quite slow compared to the rest of java code. So I was wandering if replacing by JShell would speed performances up. – greg Oct 12 '17 at 07:11
  • To answer the second part of your comment (Why I cannot conclude that...). I just don't know enough about JVM and JShell **to be sure** that the byte code will be managed by the compiler in the same way as "normal java code". – greg Oct 12 '17 at 08:38
  • 1
    The actual question is why on Earth does it have to be a scripting language/environment for something that is “compiled and then executed millions of times”. If you want to be sure to get the same performance than ordinarily compiled Java classes, *use* ordinarily compiled Java classes. The [compiler API](https://docs.oracle.com/javase/8/docs/api/?javax/tools/package-summary.html) exists since Java 6. – Holger Oct 12 '17 at 08:48
  • I totally agree, but as you are aware sometimes you inherit a software having a long history and sound decisions in the past are now obsolete... Also in our specific context it is(was) quite flexible to enable users (scientific developers) to write their code without having to deploy again the package on the cluster. But this indeed comes at a very high cost. – greg Oct 12 '17 at 08:58

0 Answers0