Fork me on GitHub
#clojurescript
<
2019-01-30
>
jstaab00:01:05

Hey all, I'm trying to do some general profiling to find bottlenecks in a shadow-cljs node app. Ideally I'd like to just flip a flag when testing and get a report. I've fiddled with a number of inbuilt nodejs profiling options, but they're all too low-level or don't use my source maps or what have you. I found tufte, which is kind of nice, but I'd rather not whitelist forms for my current purposes, and I got lots of errors when I added it to my project. Is there a good way to do this? Alternatively, is there a way to crawl a namespace and wrap functions defined there with my own profiling code?

thheller10:01:56

you can run your node script with node --inspect-brk your-script.js and open . that'll let you use the chrome devtools to profile stuff. maybe that helps?

rboyd00:01:00

@jstaab I had something similar going in a clj project for walking a ns and instrumenting fns for https://github.com/xsc/iapetos

rboyd00:01:04

let me see if I can find it

jstaab00:01:43

nice, thanks @rboyd that looks like a good start

🚀 5
jstaab00:01:29

@rboyd have I read correctly that that implementation relies on alter-var-root to do the instrumentation? I don't believe that lives in clojurescript

jstaab00:01:40

Any idea how I might get around that?

jstaab01:01:15

So far I have

jstaab01:01:19

(defmacro instrument-ns! [ns-sym]
  `(doseq [[k# v#] (ns-publics '~ns-sym)]
     (set! (symbol '~ns-sym k#) :whatever)))

jstaab01:01:32

And I get set! target must be a field or a symbol naming a var

jstaab01:01:28

I imagine it's because I'm doing this dynamically, and I'm not in macroland at the point I call set!, but I'm not sure how to get my ns-publics result from clojure, since if I call it outside the syntax quote it says the namespace doesn't exist

borkdude08:01:51

You can look at the source of spec to see how that’s done

jpmonettas14:01:21

Hello everybody! Why are type functions different for Clojure and ClojureScript? Why does ClojureScript type doesn't support the :type meta? Clojure type

(defn type 
  "Returns the :type metadata of x, or its Class if none"
  {:added "1.0"
   :static true}
  [x]
  (or (get (meta x) :type) (class x)))
Clojurescript type
(defn type
  "Return x's constructor."
  [x]
  (when-not (nil? x)
    (.-constructor x)))

erwinrooijakkers19:01:50

Does anyone know a ClojureScript app that can be used to teach beginners?

john20:01:45

This one's a classic https://github.com/bhauman/flappy-bird-demo-new and showcases the awesomeness of hot-code reloading at the repl

john20:01:41

But there are a whole host of "learning modules" that run on https://www.maria.cloud/ if you open the side panel on the left. Mostly about learning clojure in general, but runs on a self-hosted clojurescript instance right in the browser.