Clojure swing app startup time
Asked Answered
P

1

4

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.

Puffer answered 14/7, 2013 at 23:59 Comment(0)
R
2

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.

Reconnaissance answered 15/7, 2013 at 8:57 Comment(2)
It doesn't compile all of the clojure code to bytecode in the compile step (ie while the jar is being made)? Is there a way to force it to? would adding :gen-class to the ns clause help?Puffer
It might help a bit. But there's lots of other code (e.g. libraries) that isn't pre-compiled with gen-class. YMMV.Reconnaissance

© 2022 - 2024 — McMap. All rights reserved.