This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-16
Channels
- # aleph (1)
- # announcements (16)
- # babashka (36)
- # beginners (62)
- # calva (15)
- # cider (21)
- # cljsrn (5)
- # clojure (84)
- # clojure-dev (3)
- # clojure-europe (22)
- # clojure-italy (2)
- # clojure-nl (2)
- # clojure-uk (3)
- # clojurescript (36)
- # core-async (2)
- # cursive (4)
- # datomic (8)
- # emacs (14)
- # events (1)
- # fulcro (4)
- # hyperfiddle (6)
- # introduce-yourself (3)
- # jobs (1)
- # leiningen (4)
- # lsp (100)
- # nrepl (3)
- # off-topic (36)
- # pathom (17)
- # podcasts (1)
- # polylith (4)
- # portal (14)
- # react (1)
- # reagent (3)
- # reitit (8)
- # releases (3)
- # remote-jobs (1)
- # reveal (7)
- # shadow-cljs (19)
- # sql (16)
- # web-security (3)
We now have an "official" badge that you can use in your libraries or projects to indicate that it runs with babashka: https://github.com/babashka/babashka#projects Thanks to @rahul080327

observation without analysis:
`bb` startup is nearly instant when run in succession, but when I open a new iTerm, it takes an extra 500ms on the first time~
aaaand I withdraw that anecdote ^ it's due to my lazy loaded powershell10k zsh profile

Another situation in which the first invocation of bb might be slower is when it fetches deps declared in bb.edn
A demo of fs/walk-file-tree
, walk the tree for finding all .git
dirs:
https://gist.github.com/borkdude/123ad8a889e3261178054ee3867a8a3c
I came up with that example because someone complained about the performance of fs/glob
compared to find
, but it turned out that using find
you can filter on file type and you can prevent doing the glob, which is why it's faster. If you do that manually using fs/walk-file-tree
the bb example is several times faster.
it's implemented on top of fs/walk-file-tree
which is in turn implemented on top of the java nio stuff
I guess we could make fs/glob
take an ordinary predicate instead of a glob too, or make a variation
I'm just not a fan of the APIs that require mutation in userspace code (the one that takes a https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/FileVisitor.html)
It's running already over a minute long here:
$ time bb -e '(count (filter #(= ".git" (fs/file-name %)) (file-seq (io/file "."))))'
Yes, that example was a performance optimization over using the non-mutative fs/glob
:)
This is the "recommended" approach if you don't care about performance vs find
:
$ bb -e '(time (count (filter fs/directory? (fs/glob "." "**/.git" {:hidden true}))))'
In babashka.fs
I didn't try to make things fancy, it's just a thin layer over java nio, generally
Doesn't Files/walk
basically do what file-seq
does? What's the advantage of using the former?
This works:
bb -e '(-> (java.nio.file.Files/walk (.toPath (io/file ".")) (into-array java.nio.file.FileVisitOption [])) (.iterator) (iterator-seq))'
But then you still need to filter out the things you want.Yeah, but it's much much slower. Terminating early makes the example 4x faster, which was the original argument with someone on Twitter vs find
;)
$ time bb -e '(-> (java.nio.file.Files/walk (.toPath (io/file ".")) (into-array java.nio.file.FileVisitOption [])) (.iterator) (iterator-seq) (count))'
192654
bb -e 0.52s user 1.74s system 48% cpu 4.699 total
But yeah, Files/walk
is much faster than file-seq
which still doesn't terminate after a minute on my home dir :)