Fork me on GitHub
#cljs-dev
<
2022-07-16
>
john22:07:34

To follow up on my prior request, I think soon I'll be exploring implementing a new PR to CLJS for a new target, :with-webworker which will spit out both a main.js and a main-worker.js, so that an in core spawn fn (or one provided in a lib) can depend on there being a shim available. Or maybe just always produce the shim for every build if it's really cheap. Reason being, in-mesh is shaping up to be pretty powerful:

(let [a @(future 1)
      b @(future 2)
      c @(future 3)]
  (println :values [a b c])
  [a b c])
;:values [1 2 3]
;=> [1 2 3]
And more to the point, I ported injest's auto-parallizing macro =>> to inmesh and it makes a super low bar to improving performance through webworkers:
(defn flip [n]
  (apply comp (take n (cycle [inc dec]))))

(->> (range 1000000)
     (map (flip 100))
     (filter odd?)
     (map (flip 100))
     (map inc)
     (map (flip 100))
     (apply +)
     (println)
     time)
;"Elapsed time: 11452.300000 msecs"
;=> 250000500000

(=>> (range 1000000)
     (map (flip 100))
     (filter odd?)
     (map (flip 100))
     (map inc)
     (map (flip 100))
     (apply +)
     (println)
     time)
;"Elapsed time: 5615.500000 msecs"
;=> 250000500000
So it's moving beyond the toy benefits of syntactically and semantically synchronous control flow and into legitimately ergonomic performance improvements. But I still can't just require in in-mesh into injest and then provide the =>> macro to CLJS consumers without also copying over chapters of documentation from the in-mesh repo (which don't exist yet) explaining how you have to set up at least 2 builds, or 3 for more convenient repling, which will be different for each of the different build tools. It's the messiest part of the whole situation. It's a pretty complicated problem, so IDK yet if I'll come up with some thing that makes a lot of sense and that everyone will agree to, across all the different build tools, WRT one common impl of a spawn fn that will automatically Just Work across all possible build tools and build configurations. I'll let y'all know if I come up with anything, but if anything comes to mind, please do reach out or ping me here with your ideas.