ClojureScript – Performance – Goroutines



ClojureScript – Performance – Goroutines

0 0


confluence-cljs

Slides for CLJS lightning talk at http://www.meetup.com/TechConfluence/

On Github kurtharriger / confluence-cljs

ClojureScript

ClojureScript is Clojure compiler that emits javascript.

Why ClojureScript?

(not (like? you parens))

Performance Goroutines

Performance

TodoMVC example:

I think ClojureScript + React will be faster than all existing solutions in JavaScript, even JS programs using React - no qualifications

The big idea is that ClojureScript has pure values - thus computing the tree diff can always be done in logarithmic time - we just need to pointer equality tests and we only need to ever compute children lazily down the part of the tree that actually changed.

David Nolen, Author of ClojureScript Om

Goroutines

A goroutine lightweight thread of execution

Threads?

(def c (chan))
(go (while true (<! (async/timeout 250)) (>! c 1)))
(go (while true (<! (async/timeout 1000)) (>! c 2)))
(go (while true (<! (async/timeout 1500)) (>! c 3)))

(def model (atom []))
(go (while true (let [msg (<! c)] (swap! model conj msg))))

						

Getting started

Local Setup

(defproject cljs "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.5.1"]
                 [org.clojure/clojurescript "0.0-2138"]
                 [org.clojure/core.async "0.1.267.0-0d7780-alpha"]
                 [reagent "0.2.0"]]
  :plugins [[lein-cljsbuild "1.0.1"]]
  :cljsbuild {:builds [{:source-paths ["src-cljs"]
                        :compiler {:output-to "cljs/demo.js"
                                   :output-dir "cljs"
                                   :optimizations :none
                                   :pretty-print true}}]})
						

$ lien cljsbuild auto

Then run LiveReload to see changes as you make them!

Thanks!!

Kurt Harriger

kurtharriger@gmail.com

@kurtharriger