This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-06
Channels
- # beginners (3)
- # boot (2)
- # cljs-dev (11)
- # cljsrn (122)
- # clojars (9)
- # clojure (8)
- # clojure-austin (5)
- # clojure-korea (1)
- # clojure-russia (3)
- # clojure-spec (7)
- # clojure-uk (14)
- # clojurescript (45)
- # cursive (12)
- # emacs (7)
- # euroclojure (1)
- # hoplon (285)
- # instaparse (1)
- # klipse (37)
- # leiningen (1)
- # off-topic (3)
- # om (11)
- # onyx (4)
- # re-frame (5)
- # reagent (1)
- # sql (3)
- # uncomplicate (2)
- # untangled (17)
- # vim (5)
Hey all! I've written and profiled some cljs and found that a reduce operation over a large vector is my current bottleneck. I've tried converting that vector to a js array so I can use areduce, but the cost of the conversion seems equal to the speed gain from areduce.
Here's the full code: https://gist.github.com/r00k/dff143520347676514ac40d03c55260f
Do I have any other options for speeding up the summation of a large (40k elements) vector?
@ben-orenstein you could write it tediously inlined with loop
and see if that makes a difference
no higher-order functions
yeah, i’m not surprised that the conversion undoes your speed gain, i’ve done the same thing
i am not an expert on transducers, but i’m going to sketch out something that you could try - if you do try it, let me know whether it worked or whether i shouldn’t try to give advice on slack after dinner+beers with friends
anyway whatever. what i’m trying to communicate is that i hear that doing (into [] (map foo) bar)
is faster than (map foo bar)
, particularly if you’ve got a pipeline of several map/reduce operations rather than just the one (map foo)
operation
note that the invocation that gives you nice performance is (into [] (map foo) bar)
, not (into [] (map foo bar))
so if you can figure out the right syntax to chain your maps+reduces together and feed them to into
, i recommend giving that a shot and measuring the performance before+after
(my understanding of this stuff is limited - this may only be relevant for situations where you’ve got a lot of maps/filters and not be relevant for reduce)
also i just tinkered around in planck and it looks like (apply + squares) is much faster than (reduce + squares) when squares is a super large vector. ok i’m turning off slack for the night before i get myself into any more trouble, good luck 🙂
@ben-orenstein Fooling around in non-`:advanced`, it looks like the calculation is dominated by the diffing and squaring, as opposed to the summation. If you fuse the two operations, you can shave off some time.
(defn calculate-fitness' [reference-image-data individual-image-data]
"Takes two vectors of ints 0-255, representing the rgba data for our
reference image and individual-image-data. Returns the sum of squares
difference between the two, which represents how similar the two images are."
(let [squared-diffs (map (fn [a b] (let [d (- a b)]
(* d d)))
reference-image-data individual-image-data)
sum-of-squares (apply + squared-diffs)
maximum-difference (* (count reference-image-data)
(* 256 256))]
(- 1 (/ sum-of-squares maximum-difference))))
Does anyone have any favourites or recommendations for approaching the consumption of a JSON-yielding HTTP API in cljs?
@rovanion well, popular appraoches for dealing with asynchrony are core.async and promise libraries (such as promesa)
what is specific to HTTP or JSON in your problem ?
We've got a REST API, if such a thing exists, that takes and delivers JSON. Nothing special about it really.
So perhaps in other words. Is there any one of the three httpurr, cljs-http and happy which is more suited for use with core.async? I see that httpurr has promises built in and that cljs-http returns core.async channels.
@rovanion I don't think there's much at stake in the choice of the HTTP client library. My advice: pick an asynchrony paradigm which suits your application architecture, then pick an http library which is adapted to that paradigm (and still gives you all the configuration knobs you need, such as encoding formats, that's actually the more important thing as making a promise or core-async adapter really won't be hard in any case).
Personally, I like using core.async channels which receive either a value or an Error. Not everyone does
Hi guys, my code is throwing Uncaught TypeError: Cannot read property 'cljs_test_each_fixtures' of undefined
at me (running tests in figwheel) at random places. Any idea where that might come from?
Hi all, I'm a clojure noob, and I'm using http://clojure.java.io in a clojure library, but only reading files into data structures at compile time. I'd like to read the same files (at compile time) in a clojurescript program. I've read that it's possible to use clojure IO at compile time, but am unsure how to do it. Can anyone point me to a simple example?
@dbsgtk I think that would just be a macro
(defmacro read-file [] (slurp file))
and then (def file-contents (read-file))
When I run in-ns
in a clojurescript repl, does the fact that I can now references functions/variables in that particular namespace have anything to do with the analyzer keeping track of the namespace I'm supposed to be in and pre-pending that to all of my js calls? That is, has the Google Closure compiler already brought in all of my namespaces into the global context, so we can reference every function/variable by their full namespace?
I've been trying to figure out how to create a js repl that had similar capabilities to the cljs repl, and being able to easily move between namespaces is one of the things I would love in the js world
(There's more the the cljs compiler, for sure, this was just the first place I decided to start looking)
@mfikes I'm confused by the invocation of goog.provide in cljs.repl if the namespace is missing from the analyzer (https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/repl.cljc#L679)
or maybe I should say, what affect does changing cljs.analyzer/cljs-ns have on evaluation?
@futuro: I gotta run, but the answers in this SO might help partially answer your question. http://stackoverflow.com/questions/35709098/using-required-namespace-in-the-repl