任何Clojure实现可以快速启动? [英] Can any Clojure implementation start fast?

查看:161
本文介绍了任何Clojure实现可以快速启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ time java -jar clojure-1.4.0.jar -e'(printlnHello world)'
Hello world

real 0m4.586s

$ time python clojure.py -c'(py / printHello world)'

real 0m14.690s

$ time mono Clojure.Main.exe -e'(printlnhello world)'
hello world

real 0m4.843s

/ * clojure-metal由于当前没有被写入而没有被测试* /

Clojure启动时间很少,喜欢当我运行Perl或Python脚本吗?是缓慢的启动时间一个底层框架的或Clojure的问题(可以固定的早或晚)还是设计?

注意:我已经知道start-persistent-

解决方案

启动时间主要是因为Clojure本身所做的工作初始化条件。这些任务中的一些是相当重要的,例如。加载和编译核心Clojure命名空间。在不同的平台实现上运行不会真正改变这一点。



但是,未来有一个很大的优化潜力:




  • Clojure本身的大部分可以提前编译

  • Clojure编译器本身的性能可以提高

  • 延迟加载和/或编译可以减少感知延迟(可能是最大的胜利:大多数代码不需要clojure.core和其他依赖项中的所有命名空间,或至少不是立即)

  • 有人非常聪明可能想出如何进行并行加载和编译。



JVM经常(不公正地)被指责,JVM在这里很大程度上是不相关的:现代JVM的启动时间约为0.1秒。



我实际上利用这个在Clojure中编写的GUI应用程序:通过用纯Java写入启动代码,用 main 方法,你可以有一个启动屏幕和你的GUI的第一个屏幕出现得很快,然后加载Clojure以及你的应用程序代码的其余部分在后台。


$ time java -jar clojure-1.4.0.jar -e '(println "Hello world")'
Hello world

real    0m4.586s

$ time python clojure.py  -c '(py/print "Hello world")'

real    0m14.690s

$ time mono Clojure.Main.exe -e '(println "hello world")'
hello world

real    0m4.843s

/* clojure-metal is not tested due to not being written at the moment */

Can Clojure startup time be little, as like when I run Perl or Python scripts? Is slow startup time an underlying framework's or Clojure's issue (which can be fixed sooner or later) or it is by design?

Note: I already know about start-persistent-server-than-connect-to-it workaround.

解决方案

The startup time is mostly because of the work that Clojure itself does in terms of initialisation. Some of these tasks are quite significant, e.g. loading and compiling the core Clojure namespaces. Running on different platform implementations won't really change this.

However, there is a big potential for this to be optimised in the future:

  • Large parts of Clojure itself could be ahead-of-time compiled
  • Performance of the Clojure compiler itself could be enhanced
  • Lazy loading and/or compilation could reduce the perceived latency (possibly the biggest win: most code doesn't need all of the namespaces in clojure.core and other dependencies, or at least not immediately)
  • Someone very clever may figure out how to do parallel loading and compilation

Note that although the JVM is often (unjustly) blamed, the JVM is largely irrelevant here: modern JVMs have a startup time of about 0.1secs.

I actually exploit this for GUI apps written in Clojure: by writing the startup code in pure Java with a main method, you can have a splash screen and first screen of your GUI appear pretty much immediately, and then load Clojure along with the rest of your application code in the background.

这篇关于任何Clojure实现可以快速启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆