Should I use Groovy's @CompileStatic if I'm also using Java 7

我们两清 提交于 2019-12-04 01:34:07

The indy version is fully dynamic Groovy, as it is known, only faster thanks to JDK 7 invokedynamic. @CompileStatic means static compilation. While faster than normal Groovy, it can compile only a subset of Groovy and behaves a bit different. Especially all the dynamic features are not available anymore. So if you want to use dynamic features then indy is the only option. If you will be a static guy and only use a small part of the language, then @CompileStatic can be used.

Fibonacci is btw not a test in which invokedynamic can shine. The indy port is not always better. But if you do for example a lot with meta programming, then indy will be better.

You have to decide according to your usage in the end

To boil it down, @CompileStatic removes some Groovy dynamic runtime functionality in favor of speed.

So, theoretically:

  • JDK7 should be faster than JDK6 because of invokedynamic
  • @CompileStatic should be faster than Standard because some overhead and features are removed.

All that with the caveat that it will largely depend on what you are doing, as various features are optimized to different degrees.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!