This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-30
Channels
- # adventofcode (3)
- # announcements (4)
- # babashka (42)
- # beginners (56)
- # biff (23)
- # cider (8)
- # clj-yaml (2)
- # cljdoc (16)
- # clojure (83)
- # clojure-europe (52)
- # clojure-nl (3)
- # clojure-norway (4)
- # clojure-sweden (2)
- # clojure-uk (2)
- # clojurebridge (1)
- # clojurescript (2)
- # cloverage (1)
- # cursive (11)
- # data-oriented-programming (1)
- # deps-new (2)
- # dev-tooling (2)
- # emacs (3)
- # etaoin (4)
- # events (5)
- # fulcro (5)
- # gratitude (3)
- # java (3)
- # jobs (1)
- # jobs-discuss (1)
- # joyride (33)
- # malli (16)
- # music (1)
- # nbb (1)
- # nrepl (4)
- # nyc (1)
- # off-topic (25)
- # pathom (8)
- # re-frame (1)
- # reitit (7)
- # remote-jobs (2)
- # shadow-cljs (6)
- # tools-deps (9)
I have worked on including spec.alpha as a pre-compiled built rather than an https://github.com/babashka/spec.alpha but there are some edge cases I haven't had time to find out yet. The optional library works better but is interpreted, thus slower. As a compromise, I'm going to include the sources of the library in the bb binary which should add no more than 100kb or so, and this will make the UX of not having to include spec.alpha separately better, while having the same perf as before, with only marginal extra binary size.
Nice idea. Is there a big difference in loading time for a source from the filesystem vs a source in the binary itself?
no, the same. I could pre-compile the interpretation though, (by evaluating the source in bb at compile time)
Ah i see, nice trick
the trade-off here is that currently I've put these "internal sources" at the end of the classpath to they are easy to override if you still include the library yourself
I think I'll leave it like this for now since moving the evaluation to compile time requires more changes
Makes sense. But sound like useful tricks to keep in mind
Made the refactor. Binary size before:
$ ls -lat ./bb
-rwxr-xr-x 1 borkdude staff 72399695 Nov 30 11:47 ./bb
Now trying the compile time change...ah right, that doesn't work, since some things can't be initialized at build time, like java.net.http classes
(def class-map
"A delay to delay initialization of java-net-http classes to run time, since GraalVM 22.1"
(delay (persistent! (reduce (fn [acc c]
(assoc! acc c (Class/forName (str c))))
(transient class-map*) (when features/java-net-http?
java-net-http-classes)))))
new binary size:
$ ls -lat ./bb
-rwxr-xr-x 1 borkdude staff 75537359 Nov 30 13:11 ./bb
hmmmbut the loading time of spec got a lot better, but the cost seems to be 3mb or so.. which is almost equal to having it as a compile time thing
I think the built-in source + low image size addition strikes the right balance for convenience and as little bloat as possible. When spec non-alpha ever comes out, I'll include it as a fast built-in
if only the tests wouldn't fail for non-obvious reasons... https://app.circleci.com/pipelines/github/babashka/babashka?branch=spec-built-in
They are running on the same linux and JVM version, yet I get different output for:
$ clojure -M:babashka/dev test-resources/babashka/file_location1.clj
----- Error --------------------------------------------------------------------
Type: java.lang.ArithmeticException
Message: Divide by zero
:/$ time ./bb -e "(time (require '[clojure.spec.alpha :as s])) (s/def ::int int?) (s/valid? ::int 3)"
"Elapsed time: 52.029708 msecs"
true
./bb -e 0.06s user 0.01s system 91% cpu 0.075 total
I recently started using babashka for our git hooks and wrote up the process. I think it's extremely convenient :) https://blaster.ai/blog/posts/manage-git-hooks-w-babashka.html
wow thanks!
@U01V67SBM55 You can mention articles like this in #C8NUSGWG6 for. more exposure, if you want
@U01V67SBM55 implementing this immediately!
Thanks @U04V15CAJ posted there too 🙂
https://github.com/babashka/babashka: Native, fast starting Clojure interpreter for scripting
1.0.167: the ultimate Advent of Code edition!
https://github.com/babashka/babashka/blob/master/CHANGELOG.md
In the newest babashka (1.0.167) you can do this without having a fork of clojure.spec in your bb.edn
$ bb -e "(require '[clojure.spec.alpha :as s]) (s/valid? int? 2)"
true
Is there a way to use tasks in babashka in such a way that if a task fails, the task depending on it does not get executed?
im trying to write transit in a bb script, i'm not sure how to do it and cant find an example. ive tried
(with-out-str
(transit/write ( *out*) "foo"))