Very slow resource loading time with compojure route/resources and ring

718 views Asked by At

Disclaimer: I am very new to clojure.

I am suddenly running into a issue where loading my clojurescript app takes over 15 seconds just to load all of the library code. A second project, set up the same way, is not having these issues.

enter image description here

CLJS build:

  :cljsbuild {:builds [{:id "dev"
                        :source-paths ["src/cljs"]
                        :compiler {:output-to "resources/public/app/js/app.js"
                                   :output-dir "resources/public/app/js/out"
                                   :optimizations :none
                                   :source-map true}}]}

handler.clj

  (GET  "/" [] (resource-response "index.html" {:root "public/app"}))
  (route/resources "/" {:root "public/app"})
  (route/not-found "Not Found"))

My first thought is, that it somehow re-compiles everything every time I access the page, but the file timestamps of unchanged libraries didn't change.

Second thought was, that it is probably because of cache killing in my browser, but even after allowing cache through the developer tools, file loading time is still snailspeed.

Third thought was the compojure version difference between the 2 projects, but even after upgrading the 2nd project to latest, or downgrading 1st project to previous version, the issue still persists.

When monitoring, I also noticed the java process to jump to 350% CPU on page access.

I tried to revert all changes I made but can't figure out where the problem is. Being very new to clojure and clojurescript, I am out of ideas. I obviously can't wait 15 seconds with every page load just to see a message in the console.

/ EDIT:

Project.clj

(defproject picky "0.1.0-SNAPSHOT"
  :description "project"
  :url "http://example.com/FIXME"
  :source-paths ["src/clj"]
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [org.clojure/tools.reader "0.8.2"]
                 [org.clojure/clojurescript "0.0-2371"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                 [ring/ring-core "1.3.1"]
                 [ring/ring-json "0.3.1"]
                 [compojure "1.2.1"]
                 [korma "0.4.0"]
                 [org.postgresql/postgresql "9.2-1002-jdbc4"]
                 [com.cemerick/friend "0.2.1"]
                 [lobos "1.0.0-beta3"]
                 [cljs-http "0.1.20"]
                 [secretary "1.2.1"]
                 [om "0.3.6"]
                 [com.facebook/react "0.8.0.1"]
                 [hiccup "1.0.5"]]
  :plugins [[lein-cljsbuild "1.0.3"]
            [lein-ring "0.8.13"]
            [lein-pdo "0.1.1"]]
  :aliases  {"up"  ["pdo" "cljsbuild" "auto" "dev," "ring" "server-headless"]}
  :ring {:handler myapp.handler/app}
  :profiles
  {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                        [ring-mock "0.1.5"]]}}
  :cljsbuild {:builds [{:id "dev"
                        :source-paths ["src/cljs"]
                        :compiler {:output-to "resources/public/js/app.js"
                                   :output-dir "resources/public/js/out"
                                   :optimizations :none
                                   :source-map true}}]}

Middlewares are wrap-json-body and wrap-json-response, although I tried already disabling both.

1

There are 1 answers

3
patchrail On BEST ANSWER

I found the culprit of this huge performance loss. After a ton of debugging I found out that the only difference between project 1 and project 2 is the resources folder.

Project 1 includes a entire frontend project. A lot of files through bower, scss, compiled css, compiled cljs and so on. Everything you need for good frontend development. In total 10506 files.

Project 2 was a test project including a few HTML, javascript and compiled cljs files. 142 files in total.

For testing, I moved some files out of the resources folder and ta-daa, file load is down to a few milliseconds. Move the files back into the resources folder, performance get tanked up.

I am going to file a bug report at the compojure project. Might be something they weren't aware of yet.