Fork me on GitHub
#clojurescript
<
2016-07-24
>
majenful09:07:46

When I start figwheel, I have a repl in my term, but when I connect with cider (cider-jack-in), it doesn’t connect to the repl

majenful09:07:08

same in browser, I cannot evaluate (+ 2 3) in Chrome’s console

krchia20:07:24

i’m trying to optimize a function and i realize that i don’t know the cost of clojure(script) functions - can anyone direct me as to where i can learn how expensive operations like map, apply, into are? (even if optimization is not the right way here, my curiosity has been piqued anyway and i’ll like an answer just to that question)

darwin23:07:45

@krchia: in general clojurescript functions are normal js functions, what makes them adding more overhead is 1) use of persistent data structures 2) protocol methods dispatch 3) dynamic multi-method dispatch 4) complexity of core library methods/macros (e.g. how map, into or apply are implemented) I don’t know any source where you could learn how expensive individual operations are, because a) in advanced mode, code can be inlined/simplified by google closure :advanced optimisations b) both clojurescript and closure compiler are moving targets constantly improving I would recommend you to use general javascript performance tools from Chrome DevTools to inspect and optimise specific piece of code.

darwin23:07:03

If you want to get general sense how complex code gets generated from your cljs sources, read cljs.core library functions' implementation and inspect generated javascript code.

bhauman23:07:04

@darwin and whoever else is listening I think came up with and intuitive way to control which browser window gets the eval in figwheel

bhauman23:07:53

Problem: figwheel broadcasts its evals to all listening repls with the same build id

bhauman23:07:28

and you get back the first response

bhauman23:07:16

I'm now thinking that I can use js/document.hidden as a simple and effective way to determine which tab and or client will eval the messages

bhauman23:07:25

basically the client that is has a tab focussed will eval the repl code

bhauman23:07:15

this still allows multiplexing repl commands to say different browsers or instances of browsers if that is what you want

bhauman23:07:27

The iphone and the the local web browser will still get and evaluate the repl messages but when operating in a single browser only the tab that is open will get it.

darwin23:07:34

@bhauman: this is a nice discovery, will definitely help to improve figwheel workflow

darwin23:07:22

works for tabs only, not for focus, I think, for example opening two windows side-by-side, both report document.hidden as false

bhauman23:07:51

that is the case

bhauman23:07:10

I could use last focus as a tie breaker but that could get nutsy

bhauman23:07:49

this doesn't fix the whole problem but it goes a long way towards intuitive sensible behavior

bhauman23:07:21

there is still a case where this doesn't work and that is when the window is hidden and you are still expecting eval to work

bhauman23:07:32

oh shoot must think harder

darwin23:07:36

@bhauman: just for inspiration, in Dirac I implemented a simple string/regex matching between browser sessions and REPL instances: https://github.com/binaryage/dirac/blob/master/docs/integration.md

darwin23:07:54

you can “join” a dirac session by giving it regex or substring match, the connection is then maintained dynamically (browser session can disappear and reappear later)

bhauman23:07:30

that makes sense

darwin23:07:52

I use only the first match, but in your case you could broadcast to all matches, and default matching strategy would be the build-id (to maintain original behaviour)

darwin23:07:51

if someone wanted to target only iphone, it would match against platform in the session string

bhauman23:07:16

yeah I get it

darwin23:07:21

if they wanted to target only specific tab on desktop, they could match url (or add a hash/param to their url, to match to)

bhauman23:07:27

smart and it makes sense

bhauman23:07:20

I'm going to let it steep in

bhauman23:07:41

I think a combination of ideas, a sane default where the developer doesn't have to do anything and a proactive method of selecting the client makes sense

bhauman23:07:59

the regex idea is as good as any

darwin23:07:14

this is where I build the session string[1], you would want to add build-id and maybe some other figwheel specific info: [1] https://github.com/binaryage/dirac/blob/master/src/runtime/dirac/runtime/core.cljs#L59