Fork me on GitHub
#babashka
<
2024-01-16
>
Ingy döt Net13:01:22

A major selling point for bb, is it is basically a fast starting clojure. Since it is graal compiled it is limited to certain ostype/machtype usage. I was wondering if that was one of the primary reasons for nbb? A fast starting clojure that can run anywhere nodejs can (freebsd etc).

borkdude13:01:20

nbb is intended to be used as bb but by leveraging the Node.JS ecosystem in mind. There are JS libraries for about anything (reading excel files, or whatever) and that may not always be the case for bb. It's just another way to increase the reach of Clojure via scripting

borkdude13:01:53

you can run nbb anywhere you can run node, indeed:

npx nbb

Ingy döt Net13:01:33

The other day you mentioned that SCI works in cljs, which I hadn't realized. I'm hoping that making cljs builds of ys might allow it to get to more platforms. But the ability to also leverage JS npm libs is exciting too.

borkdude13:01:06

yep, that is supported by SCI (given enough configuration ;))

borkdude13:01:44

nbb is one such project, #C034FQN490E is another one that uses SCI+JS, and #C03DPCLCV9N (VSCode scripting) another one

Ingy döt Net13:01:42

given that bb can't dynamically use java libs, are there things that bb can do that nbb can't?

borkdude13:01:23

bb is just closer to JVM semantics, so it's easier to share code between Clojure (JVM) and bb. ClojureScript is less popular than Clojure

borkdude13:01:52

The thing that bb can that nbb can't mostly has to do with the target platform (multi-threading etc) (and vice versa)

borkdude13:01:36

the stuff that makes nbb more complicated is that JS needs async to load libs (if you want to load ES modules). This is why sci.async (https://github.com/babashka/sci/blob/master/doc/async.md) was written

borkdude13:01:10

I'm also working on an alternative CLJS compiler which can be integrated in a (normal) CLJS app for dynamic evaluation: https://squint-cljs.github.io/cherry/ (playground takes a while to load due to import-maps / CDN stuff) This performs better than SCI (interpretation vs compilation)

borkdude13:01:24

The thing that the cherry compiler simplifies is that you can just compile to import .. from "whatever" and don't worry about async loading of JS libraries yourself

Ingy döt Net13:01:54

$ time bb -e nil

real	0m0.033s
user	0m0.010s
sys	0m0.024s
$ time nbb -e nil

real	0m0.174s
user	0m0.150s
sys	0m0.029s

borkdude13:01:22

yeah, you can speed up the node bit a bit btw

borkdude13:01:40

depending on how you installed it

borkdude13:01:51

if you run node_modules/.bin/nbb directly it's much faster

borkdude13:01:22

or wait, maybe that's not true, it was npx which is slow

borkdude13:01:58

with npm install -g nbb@latest I get:

$ time nbb -e '(+ 1 2 3)'
6
nbb -e '(+ 1 2 3)'   0.10s  user 0.02s system 95% cpu 0.119 total

borkdude13:01:27

yeah that's another benefit of bb over nbb, graalvm is just snappier to start up

Ingy döt Net13:01:50

$ which nbb
/home/ingy/.nvm/versions/node/v16.13.1/bin/nbb

borkdude13:01:07

try a newer node version (21 is LTS now), it might be somewhat faster

Ingy döt Net13:01:01

$ time node -e 1

real	0m0.041s
I remember versions where it went up to the 0.300 area

Ingy döt Net13:01:18

glad they fixed it 🙂

borkdude13:01:27

node also supports building images like graalvm, this might fix the startup issue even more, but that's another rabbit hole to get into

borkdude13:01:36

bun does too

borkdude13:01:03

$ time bun -e '1'
bun -e '1'   0.01s  user 0.01s system 89% cpu 0.019 total

borkdude13:01:19

but paradoxically bun takes longer to run nbb since it first checks if there is stuff to transpile I believe

borkdude13:01:40

anyway, good luck making trade-offs :)

teodorlu13:01:10

>

$ which nbb
> /home/ingy/.nvm/versions/node/v16.13.1/bin/nbb
NVM (node version manager) might also slow things down with the “shim to right version”

2
Ingy döt Net13:01:16

what I'm wondering most for YS is that I need to compile to a shared lib to bind to every language. if I could build a shared lib with nodejs that would be pretty rad. (target platform wise)

borkdude13:01:54

I don't know about creating a shared library, but bun lets you use shared libraries pretty easily

borkdude13:01:12

note that bun is kind of experimental, it's kind of changing at a fast pace

Ingy döt Net13:01:09

@U3X7174KS

$ time /home/ingy/.nvm/versions/node/v16.13.1/bin/node -e 1

real	0m0.049s
that's the best of 3 🤷

👍 2
borkdude13:01:27

and node 21?

Ingy döt Net13:01:56

$ time /home/ingy/.nvm/versions/node/v21.6.0/bin/node -e 1

real	0m0.029s
🙂

🎉 2
borkdude15:01:01

Forgot about this one:

time deno run -A npm:nbb -e '(+ 1 2 3)'
6
deno run -A npm:nbb -e '(+ 1 2 3)'   0.06s  user 0.01s system 62% cpu 0.115 total

borkdude15:01:23

$ time deno run -A npm:squint-cljs -e '(js/console.log (+ 1 2 3))'
6
deno run -A npm:squint-cljs -e '(js/console.log (+ 1 2 3))'   0.05s  user 0.01s system 94% cpu 0.059 total

borkdude15:01:40

with deno.json being:

{
  "imports": {
    "squint-cljs": "npm:squint-cljs",
    "squint-cljs/core.js": "npm:squint-cljs/core.js"
  }
}