Clojure swing应用启动时间 [英] Clojure swing app startup time
问题描述
我刚刚开始使用clojure和跷跷板制作一个GUI应用程序。它没有多少创建一个JFrame和几个组件。这里是代码。主函数只调用 start-gui
,只要返回就退出。
I just started making a GUI app using clojure and seesaw. It does little more that create a JFrame and a couple components. Here's the code. The main function does nothing but call start-gui
and exit as soon as it returns.
(ns pause.gui
(:use seesaw.core))
(native!)
; (javax.swing.UIManager/setLookAndFeel
; "org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel")
(def main-window
(frame :title "Pause"
:on-close :exit))
(def sidebar (listbox :model []))
(def main-area (text :multi-line? true
:font "MONOSPACED-PLAIN-14"
:text "test"))
(def main-split
(left-right-split (scrollable sidebar)
(scrollable main-area)
:divider-location 1/5))
(defn setup-main-window
"Fills the main window with its content"
[main-window]
(config! main-window
:content main-split)
main-window)
(defn start-gui
"Create the main window"
[]
(-> main-window
setup-main-window
pack!
show!))
我使用 lein uberjar
用 time java -jar
定时。它报告14.5秒。有什么我做错了吗?
I compiled this using lein uberjar
and timed it with time java -jar
. It reported 14.5 seconds. Is there something I'm doing wrong? I'm okay with 3 seconds startup but this is completely unacceptable.
推荐答案
Clojure还有很多启动时间,可悲的是。这主要是因为Clojure在所有需要的命名空间中加载时发生的编译/代码加载量。
Clojure still has quite a bit of startup time, sadly. This is mainly because of the amount of compilation / code loading that happens when Clojure loads in all the required namespaces.
对于我编写的基于Swing的GUI应用程序,我经常在Java中写入 main
入口点,以便您可以快速向用户显示初始GUI或初始屏幕 - 而应用程序/ Clojure代码的其余部分在后台加载。
For the Swing-based GUI apps that I have written, I have often written the main
entry point in Java, so that you can display the initial GUI or a splash screen quickly to the user - while the rest of the app / Clojure code loads in the background.
这篇关于Clojure swing应用启动时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!