Clojure swing app startup time

元气小坏坏 提交于 2020-01-13 11:28:10

问题


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!))

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/17644980/clojure-swing-app-startup-time

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