support for project's Leiningen jvm-opts `Xmx` vs export JVM_OPTS, "older" versions of jvm #261

Closed
trevor opened this Issue Nov 5, 2013 · 10 comments

Comments

Projects
None yet
4 participants
@trevor

trevor commented Nov 5, 2013

It seems a project's project.clj doesn't currently get passed jvm-opts memory options, but it would be very helpful.

Example:

  1. Added :jvm-opts ^:replace ["-Xms1024m" "-Xmx1024m" "-server"] to plugin/project.clj, support/project.clj, and example project's project.clj.

  2. Added two lines to support/src/cljsbuild/compiler.clj:

L46  (defn- compile-cljs [cljs-paths compiler-options notify-command incremental? assert?]
+++    (println (str "Support - Total Mem: " (float (/ (.totalMemory (Runtime/getRuntime)) (* 1024 1024)))))
+++    (println (str "Support - Max Mem: " (float (/ (.maxMemory (Runtime/getRuntime)) (* 1024 1024)))))
L47    (let [output-file (:output-to compiler-options)
  1. Added two lines to plugin/src/leiningen/cljsbuild.clj:
L43  (println "Compiling ClojureScript.")
+++  (println (str "Plugin - Total Mem: " (float (/ (.totalMemory (Runtime/getRuntime)) (* 1024 1024)))))
+++  (println (str "Plugin - Max Mem: " (float (/ (.maxMemory (Runtime/getRuntime)) (* 1024 1024)))))
L44  ; If crossover-path does not exist before eval-in-project is called,
  1. javac 1.7.0_25, no JVM_OPTS (boo)
% unset JVM_OPTS
% javac -version
javac 1.7.0_25
% lein cljsbuild once
Compiling ClojureScript.
Plugin - Total Mem: 16.667969
Plugin - Max Mem: 75.4375
Support - Total Mem: 15.324219
Support - Max Mem: 36.75
Compiling "public/main.js" from ["src-cljs"]...
Compiling "public/main.js" failed.
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
  at clojure.lang.Symbol.withMeta(Symbol.java:95)
  at clojure.core$with_meta.invoke(core.clj:214)
  at clojure.tools.reader$read_symbol.invoke(reader.clj:265)
...
  1. javac 1.7.0_25, with JVM_OPTS (yay)
% export JVM_OPTS="-Xms1024m -Xmx1024m -server"
% javac -version
javac 1.7.0_25
% lein cljsbuild once
Compiling ClojureScript.
Plugin - Total Mem: 16.664062
Plugin - Max Mem: 75.4375
Support - Total Mem: 989.875
Support - Max Mem: 989.875
Compiling "public/main.js" from ["src-cljs"]...
Successfully compiled "public/main.js" in 16.529032 seconds.
  1. javac 1.8, no JVM_OPTS (meh..)
% unset JVM_OPTS
% javac -version
javac 1.8.0-ea
% lein cljsbuild once
Compiling ClojureScript.
Plugin - Total Mem: 194.5
Plugin - Max Mem: 1820.5
Support - Total Mem: 319.5
Support - Max Mem: 1820.5
Compiling "public/main.js" from ["src-cljs"]...
Successfully compiled "public/main.js" in 16.384051 seconds.
  1. javac 1.8, with JVM_OPTS (yay)
% export JVM_OPTS="-Xms1024m -Xmx1024m -server"
% javac -version
javac 1.8.0-ea
% lein cljsbuild once
Compiling ClojureScript.
Plugin - Total Mem: 196.0
Plugin - Max Mem: 1820.5
Support - Total Mem: 982.0
Support - Max Mem: 982.0
Compiling "public/main.js" from ["src-cljs"]...
Successfully compiled "public/main.js" in 13.894869 seconds.

(re ticket #236)

@swannodette

This comment has been minimized.

Show comment Hide comment
@swannodette

swannodette Nov 5, 2013

Thanks for the report, I believe this likely a Lein issue, and it keeps coming up thanks for pushing on this one.

Thanks for the report, I believe this likely a Lein issue, and it keeps coming up thanks for pushing on this one.

@ibdknox

This comment has been minimized.

Show comment Hide comment
@ibdknox

ibdknox Nov 5, 2013

I'm fairly certain this is a simple issue with lein-cljsbuild. It creates a subproject to use for eval-in-project and doesn't include jvm-opts: https://github.com/emezeske/lein-cljsbuild/blob/master/plugin/src/leiningen/cljsbuild/subproject.clj#L65

ibdknox commented Nov 5, 2013

I'm fairly certain this is a simple issue with lein-cljsbuild. It creates a subproject to use for eval-in-project and doesn't include jvm-opts: https://github.com/emezeske/lein-cljsbuild/blob/master/plugin/src/leiningen/cljsbuild/subproject.clj#L65

@swannodette

This comment has been minimized.

Show comment Hide comment
@swannodette

swannodette Nov 5, 2013

Ok I guess it's just a question of whether people want to be able to specify :jvm-opts specific to lein-cljsbuild, thoughts @cemerick?

Ok I guess it's just a question of whether people want to be able to specify :jvm-opts specific to lein-cljsbuild, thoughts @cemerick?

@ibdknox

This comment has been minimized.

Show comment Hide comment
@ibdknox

ibdknox Nov 5, 2013

I would just set the default for the build process to be higher.

ibdknox commented Nov 5, 2013

I would just set the default for the build process to be higher.

@swannodette

This comment has been minimized.

Show comment Hide comment
@swannodette

swannodette Nov 5, 2013

@ibdknox good point

@ibdknox good point

@cemerick

This comment has been minimized.

Show comment Hide comment
@cemerick

cemerick Nov 5, 2013

Collaborator

Hrm, well, that just doesn't make much sense. v2 will just use the project's project, rather than fabricating one.

@swannodette What's a safe heap setting for the compiler to begin with? Clearly a lot of people are working without a problem using the defaults. @trevor, can you characterize the size of the project in question?

Collaborator

cemerick commented Nov 5, 2013

Hrm, well, that just doesn't make much sense. v2 will just use the project's project, rather than fabricating one.

@swannodette What's a safe heap setting for the compiler to begin with? Clearly a lot of people are working without a problem using the defaults. @trevor, can you characterize the size of the project in question?

@swannodette

This comment has been minimized.

Show comment Hide comment
@swannodette

swannodette Nov 5, 2013

256mb seems reasonable to me?

256mb seems reasonable to me?

@trevor

This comment has been minimized.

Show comment Hide comment
@trevor

trevor Nov 5, 2013

Hi @cemerick - I don't have any typical case in mind, but one of my beginner projects always throws this error.

I can reproduce with these two files:

project.clj:

(defproject abc "0.1.0-SNAPSHOT"
  :plugins  [[lein-cljsbuild "0.3.4"]]
  :jvm-opts ^:replace ["-Xms1024m" "-Xmx1024m" "-server"]
  :dependencies [[org.clojure/clojure "1.6.0-alpha1"]
                 [org.clojure/clojurescript "0.0-SNAPSHOT"]]
  :cljsbuild {
              :builds [
                       {:source-paths ["src-cljs"]
                       :compiler {:pretty-print true
                                   :output-to "public/main.js"
                                   :source-map "public/main.js.map"
                                   :output-dir "public/cljs-whitespace"
                                   :optimizations :whitespace}}]}
  :target-path ".target"
  :compile-path ".target/classes")

src-cljs/main.cljs:

(ns main
  (:require
    [clojure.browser.event]
    [clojure.browser.dom]
    [cljs.reader]
    [goog.json]
    [goog.debug]
    [goog.dom]
    [goog.ui.TableSorter]
    [goog.History]
    [goog.history.Html5History]))

;; eof

trevor commented Nov 5, 2013

Hi @cemerick - I don't have any typical case in mind, but one of my beginner projects always throws this error.

I can reproduce with these two files:

project.clj:

(defproject abc "0.1.0-SNAPSHOT"
  :plugins  [[lein-cljsbuild "0.3.4"]]
  :jvm-opts ^:replace ["-Xms1024m" "-Xmx1024m" "-server"]
  :dependencies [[org.clojure/clojure "1.6.0-alpha1"]
                 [org.clojure/clojurescript "0.0-SNAPSHOT"]]
  :cljsbuild {
              :builds [
                       {:source-paths ["src-cljs"]
                       :compiler {:pretty-print true
                                   :output-to "public/main.js"
                                   :source-map "public/main.js.map"
                                   :output-dir "public/cljs-whitespace"
                                   :optimizations :whitespace}}]}
  :target-path ".target"
  :compile-path ".target/classes")

src-cljs/main.cljs:

(ns main
  (:require
    [clojure.browser.event]
    [clojure.browser.dom]
    [cljs.reader]
    [goog.json]
    [goog.debug]
    [goog.dom]
    [goog.ui.TableSorter]
    [goog.History]
    [goog.history.Html5History]))

;; eof
@trevor

This comment has been minimized.

Show comment Hide comment
@trevor

trevor Nov 5, 2013

follow-up for @cemerick Re: 'Clearly a lot of people are working without a problem using the defaults.'

I believe this may be due to people having upgraded to newer version of Java 7, mine is a relatively older 1.7.0_25. This is based on the comment here: #236 (comment) (and that it works on 1.8)

trevor commented Nov 5, 2013

follow-up for @cemerick Re: 'Clearly a lot of people are working without a problem using the defaults.'

I believe this may be due to people having upgraded to newer version of Java 7, mine is a relatively older 1.7.0_25. This is based on the comment here: #236 (comment) (and that it works on 1.8)

@cemerick

This comment has been minimized.

Show comment Hide comment
@cemerick

cemerick Nov 5, 2013

Collaborator

FWIW, I wasn't trying to say that there isn't a problem, was just hoping you were working on a particularly large project or something.

Happy to take a patch that adds -Xmx256m to :jvm-opts in the mock project that cljsbuild uses for compilation. v2 will just use the "project's project" so people can go above that if necessary (for crazy macrology, etc).

Collaborator

cemerick commented Nov 5, 2013

FWIW, I wasn't trying to say that there isn't a problem, was just hoping you were working on a particularly large project or something.

Happy to take a patch that adds -Xmx256m to :jvm-opts in the mock project that cljsbuild uses for compilation. v2 will just use the "project's project" so people can go above that if necessary (for crazy macrology, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment