Several days ago the important event for Groovy language community has happened - Groovy 2.0 has been released. The key feature of new release is the static compilation for improving performance of the critical parts of application.
I use Groovy language for the several years and as for me, the main thing this wonderful modern JVM language was missing is the static compilation. The performance of Groovy code was very poor comparing with plain old Java code due to dynamic nature of the language. The poor performance problem restricted the usage of Groovy in many real life projects, where the speed of code execution is very important. Often developers don't need all the dynamic capabilities offered by the language, but the performance is more critical.
The first thing I was going to do when I have heard about the Groovy 2.0 release was to estimate the new statically-typed code performance. At first I wrote some performance tests manually, but a couple days ago I accidentally found an interesting Groovy benchmarking library Gbench written by Nagai Masato. It makes code performance estimation very simple and no time-consuming to write additional code.
Here is the code example that compares dynamic and static groovy code execution using GBench:
You can execute and check it using the Groovy Console:
As we can see, the execution speed of statically-typed version of fibonacci function is nearly 3 times faster than the dynamic version. With appearance of code compilation, now we can use Groovy in critical parts of application, where only Java or Scala had to be used in early times.
I use Groovy language for the several years and as for me, the main thing this wonderful modern JVM language was missing is the static compilation. The performance of Groovy code was very poor comparing with plain old Java code due to dynamic nature of the language. The poor performance problem restricted the usage of Groovy in many real life projects, where the speed of code execution is very important. Often developers don't need all the dynamic capabilities offered by the language, but the performance is more critical.
The first thing I was going to do when I have heard about the Groovy 2.0 release was to estimate the new statically-typed code performance. At first I wrote some performance tests manually, but a couple days ago I accidentally found an interesting Groovy benchmarking library Gbench written by Nagai Masato. It makes code performance estimation very simple and no time-consuming to write additional code.
Here is the code example that compares dynamic and static groovy code execution using GBench:
@Grab('com.googlecode.gbench:gbench:0.3.0-groovy-2.0')
import gbench.BenchmarkBuilder
import groovy.transform.CompileStatic
int fib(int n) {
if (n < 2) return n
return fib(n - 1) + fib(n - 2)
}
@CompileStatic
int fib2(int n) {
if (n < 2) return n
return fib2(n - 1) + fib2(n - 2)
}
new BenchmarkBuilder().run {
int n = 20
"Normal Version" { fib n }
"@CompileStatic Version" { fib2 n }
}.prettyPrint()
You can execute and check it using the Groovy Console:
As we can see, the execution speed of statically-typed version of fibonacci function is nearly 3 times faster than the dynamic version. With appearance of code compilation, now we can use Groovy in critical parts of application, where only Java or Scala had to be used in early times.
You can read about all the new version language improvements in the article What's new in Groovy 2.0 written by Groovy project lead Guillaume Laforge.

Комментариев нет:
Отправить комментарий