Fork me on GitHub
#babashka
<
2020-02-18
>
borkdude15:02:16

$ clj -e '(ns foo "an awesome namespace" (:require [clojure.repl])) (clojure.repl/doc foo)'
-------------------------
foo
  an awesome namespace
$ bb -e '(ns foo "an awesome namespace" (:require [clojure.repl])) (clojure.repl/doc foo)'
-------------------------
foo
  an awesome namespace

mogenslund21:02:15

Hi. Is there any way to read keypresses using Babashka in a Linux/Mac terminal? With Clojure on the JVM I set the terminal to RAW mode and I do something like this:

(let [r (.BufferedReader. *in*)]
   (loop [input (.read r)]
     (do something with input)
     (recur (.read r))))

borkdude21:02:17

How do you set the terminal to raw mode? I test this code:

(let [r (.BufferedReader. *in*)]
  (loop [input (.read r)]
    (prn input)
    (recur (.read r))))
with
clojure /tmp/foo.clj
and nothing happens until I press enter

borkdude21:02:40

Same code works with babashka and behaves the same

mogenslund22:02:51

I usually use ProcessBuilder in Java to execute stty -echo raw </dev/tty If I just add that to the command line it actually works :-) Something like stty -echo raw </dev/tty ; bb /tmp/foo.clj I do not know why I did not see this. I am good to go. Thank you! Now I will try to make my text editor work through Babashka :-)

borkdude22:02:53

@U0FS3RG3C was also interested in reading single characters at a time, so stex ^

borkdude22:02:24

There is an issue with the new version 20 of GraalVM on macOS: the startup time seems to be 10ms slower (which makes it 25ms instead of 13ms). Is this a problem to anyone? I don't find it very noticeable, unless you start like 100 bb scripts in sequence.

borkdude22:02:59

I can also just wait for 20.1

jeroenvandijk22:02:28

Is there a new feature that wants you to do the update anyway? I don't notice any different between 13ms and 25ms. I guess it doesn't affect the runtime performance (slower loops or similar)?

borkdude22:02:33

let me check. it does seem a little slower with v20:

$ time ./bb "(loop [val 0 cnt 1000000] (if (pos? cnt) (recur (inc val) (dec cnt)) val))"
1000000
./bb    1.98s  user 0.10s system 99% cpu 2.089 total
I'm recompiling with 19.3.1 now...

borkdude22:02:18

with 19.3.1:

$ time ./bb "(loop [val 0 cnt 1000000] (if (pos? cnt) (recur (inc val) (dec cnt)) val))"
1000000
./bb    1.59s  user 0.08s system 99% cpu 1.676 total

borkdude22:02:43

that's like 25% slower with v20

borkdude22:02:51

I'll include that in the issue

borkdude22:02:46

Would be good if someone could also test this loop on linux for 19.3.1 vs 20 - maybe @sogaiu?

sogaiu22:02:02

i'll take a look

borkdude22:02:55

thanks! I updated the issue here: https://github.com/oracle/graal/issues/2136#issuecomment-587941241 once you have this data for linux, I'll also paste it there, unless you want to yourself

borkdude22:02:35

Upgrading to v20 would open up the possibility for jdk11 which would then maybe open up the way to a built-in http client (hato, which I haven't tested yet)

borkdude22:02:31

jdk11 has problems on 19.3.1 for macos when using nio classes in the reflection.config which babashka does, that's why we cannot upgrade to jdk11 with 19.3.1 right now

sogaiu22:02:20

just to confirm, the loop testing is for the java 8 based graal (19 vs 20)?

sogaiu22:02:32

ok, thanks

borkdude22:02:53

luckily graalvm is now providing dev builds so maybe the wait isn't that long once this is fixed

sogaiu22:02:35

it's nice there are snapshots / nightlies -- good for testing whether something is fixed. not so sure if they will be good for building releases -- perhaps it will depend.

sogaiu22:02:58

(btw, the graal downloads are taking a while -- will try to test when they are done.)

borkdude22:02:39

you might be right... on the other hand, production releases also often contain bugs, so what's the difference 🙂

😅 1
sogaiu23:02:27

downloads keep dying...i don't suppose there is some way to get checksums for github releases?

borkdude23:02:22

don't know. I'm off to bed. thanks for trying so far! 💤

sogaiu23:02:04

19.3.1:

$ multitime -n10 -s1 -q ./bb "(loop [val 0 cnt 1000000] (if (pos? cnt) (recur (inc val) (dec cnt)) val))"
===> multitime results
1: -q ./bb "(loop [val 0 cnt 1000000] (if (pos? cnt) (recur (inc val) (dec cnt)) val))"
            Mean        Std.Dev.    Min         Median      Max
real        1.785       0.037       1.737       1.780       1.873       
user        1.709       0.039       1.653       1.716       1.797       
sys         0.076       0.015       0.040       0.080       0.092    

sogaiu23:02:21

20.0.0:

$ multitime -n10 -s1 -q ./bb "(loop [val 0 cnt 1000000] (if (pos? cnt) (recur (inc val) (dec cnt)) val))"
===> multitime results
1: -q ./bb "(loop [val 0 cnt 1000000] (if (pos? cnt) (recur (inc val) (dec cnt)) val))"
            Mean        Std.Dev.    Min         Median      Max
real        1.897       0.055       1.837       1.872       1.988       
user        1.819       0.044       1.762       1.800       1.889       
sys         0.078       0.015       0.052       0.078       0.100  

sogaiu23:02:24

so slower, but around 6% -- does that seem right?

sogaiu23:02:44

(this was using the master branch freshly pulled, fwiw)