Fork me on GitHub
#klipse
<
2016-10-28
>
jrheard02:10:18

@viebel - one thing i’ve run into while messing around with klipse snippets is that it’s easy to completely murder a browser tab if, while editing a snippet’s code, you accidentally make it infinite loop

jrheard02:10:27

have you run into this before / do you think it’s possible to fix?

jrheard03:10:08

signing off for the night (utc-7 🙂 ), later!

Yehonathan Sharvit03:10:37

will test it later

Yehonathan Sharvit03:10:52

I’m aware of the infinite loop issue

Yehonathan Sharvit03:10:20

1. I was expecting the browser to detect it and stop the script

Yehonathan Sharvit03:10:55

2. I mitigated it by limiting the print-length of the ouptut to 1000 (configurable) so that (range) is not crashing

Yehonathan Sharvit03:10:32

3. Someone tried to solve it by wrapping all the recur statements after macro expansion. It looks interesting. It’s here: https://github.com/oakes/eval-soup/blob/master/src/eval_soup/core.cljs#L86-L92. But it has some limitation: https://github.com/oakes/eval-soup/issues/1

Yehonathan Sharvit03:10:45

4. Do you have any ideas of your own?

Yehonathan Sharvit06:10:20

@jrheard I’ve merged your code and deployed it - KLIPSE version 4.4.0

Yehonathan Sharvit06:10:41

Now, I’m waiting for your blog past with the canvas stuff

jrheard07:10:58

nice, thanks!

jrheard07:10:04

i was thinking a timeout like figwheel’s repl’s might be a good solution

jrheard07:10:13

with a shorter timeout, like 2 seconds max instead of figwheel’s 8

jrheard07:10:20

haven’t looked into feasibility

jrheard07:10:59

will read cljs-soup in the morning, looks like it also does timeouts

jrheard07:10:20

expect the post early next week 😄

jrheard07:10:44

it’s not very complicated but i need to finish setting up my blog / etc

jrheard07:10:49

ok sleeptime

jrheard16:10:16

dang, i guess it just plain isn’t possible to kill a running function in js

jrheard16:10:39

http://stackoverflow.com/questions/17007482/how-can-i-interrupt-and-stop-a-running-function-in-javascript suggests webworkers, but you can’t touch the DOM from those, and i like being able to touch the DOM in klipse

jrheard16:10:46

so, i’m out of ideas 🙂

jrheard17:10:29

i came up with a hacky idea

jrheard17:10:31

i’m not sure if i like it

jrheard17:10:00

but if it’s possible to run cljs code in the context of web workers - and i haven’t checked to see if it is - you could use them as a sort of canary

jrheard17:10:42

so at snippet evaluation time, each klipse snippet could spin up a web worker, let it execute for up to two seconds, and if it hasn’t executed by then you know the snippet’s code will time out, so you can kill the web worker and not execute the snippet’s code in the main js thread, and show an error message in the output codemirror window

jrheard17:10:17

and if the web worker executes successfully within two seconds (i don’t know anything about web workers but i’m guessing that there’s a way to be notified if the worker completes much earlier, eg after only 5ms or something), you can be relatively sure that the code is safe to run, and so then the snippet goes ahead and runs its cljs code in the context of the main js thread

jrheard17:10:35

the main obvious badness of this “solution” is that every snippet ends up being run twice per evaluation

jrheard17:10:44

and so if it has side effects, that’s bad; and if the code it contains is very slow, then it will be twice as slow as it would have been otherwise

jrheard17:10:10

on the other hand, again i don’t know anything about web workers but i’ve heard that they can’t manipulate the DOM, so that’s a whole category of side effect that we don’t have to worry about duplicating

jrheard17:10:27

anyway this idea is probably bad, but i figured i’d mention it in case it can serve as a jumping-off point for better solutions

jrheard17:10:12

does klipse_plugin.min.js not work for clojure? i notice that it’s not listed in the clojure example of https://github.com/viebel/klipse , and i’ve had some trouble getting it to work for me

jrheard17:10:14

gonna try again

jrheard17:10:49

i get this error:

DOMException: Failed to execute 'querySelectorAll' on 'Document': The provided selector is empty.
    at Ay ()
    at By ()
    at 
    at 

jrheard18:10:36

hm, right - is this because bootstrapped cljs isn’t compatible with advanced compilation?

jrheard18:10:54

https://github.com/clojure/clojurescript/wiki/Optional-Self-hosting mentions being able to get up to :optimizations :simple

jrheard18:10:43

the regular plugin build compiles fine if i switch it from :whitespace to :simple - would that be a good change to make?

jrheard18:10:05

i see 8.1MB with the :whitespace build and 6.6MB with the :simple build

jrheard18:10:55

(i know you’re in a different timezone and it’s the weekend, don’t worry, i’m not expecting immediate responses to any of these messages - just writing them down so i don’t forget these things 🙂 )

jrheard18:10:25

it looks like the gzipped sizes are 1MB with :whitespace, 0.775MB with :simple

jrheard18:10:45

so maybe it’s not a huge deal, that’s not an extremely drastic difference, just figured i’d check to see if there’s a good reason not to use :simple for the plugin build

jrheard19:10:22

also, FYI, the twitter links at the bottom of http://blog.klipse.tech/clojure/2016/03/17/klipse.html seem to point to the wrong place

jrheard22:10:49

ok, here’s the post (in my blog staging area, please don’t share this via social media / etc yet, it won’t be living here long-term): http://jrheard.com/blog-staging/procedural-dungeon-generation-drunkards-walk-in-clojurescript/ . will prob publish it on monday morning