This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-04
Channels
- # announcements (4)
- # aws (3)
- # babashka (58)
- # beginners (59)
- # biff (6)
- # cider (3)
- # clj-kondo (48)
- # clj-on-windows (1)
- # cljdoc (1)
- # clojure (136)
- # clojure-europe (19)
- # clojure-gamedev (7)
- # clojure-germany (2)
- # clojure-nl (7)
- # clojure-norway (1)
- # clojure-portugal (1)
- # clojure-uk (4)
- # clojurescript (41)
- # community-development (2)
- # core-async (5)
- # cursive (10)
- # data-oriented-programming (1)
- # data-science (1)
- # datahike (5)
- # datomic (60)
- # docker (2)
- # emacs (13)
- # figwheel-main (19)
- # fulcro (12)
- # graalvm (9)
- # holy-lambda (41)
- # honeysql (14)
- # introduce-yourself (3)
- # jobs (4)
- # lsp (11)
- # nrepl (1)
- # off-topic (9)
- # other-languages (2)
- # pathom (22)
- # portal (5)
- # re-frame (17)
- # remote-jobs (4)
- # reveal (14)
- # shadow-cljs (1)
- # tools-build (7)
- # tools-deps (47)
- # xtdb (8)
- # yada (2)
I'm experimenting with b/compile-clj
to a) reduce repl/script startup time b) compile stuff before it goes into an uberjar (so the app starts up quicker when ran from the uberjar)
My root assumption (and please correct me if this is wrong) is that in order to make startup/warmup as quick as possible I should try and compile as many of the namespaces that need to be loaded until the app starts up and reaches a warm state so all of that loading happens quickly.
The part of the interface of b/compile-clj
that deals with including namespaces in the compile.clj script is either a fix collection of namespaces or a collection of paths (provided by the caller or extracted from the basis), which is then resolved through tools.namespace to a collection of namespaces.
As I'm looking to maximize the number of namespaces to compile, I'm planning on using this latter option. However, a lot of loading in my app(s) happen dynamically, using functions like (require)
and (requiring-resolve)
, which means that if I just provide my app's own source paths, tools.namespace won't find all the namespaces my app depends on at runtime (as it only parses ns declarations).
What I tried therefore is using all the paths from (:classpath-roots basis)
but this resulted in compile.clj also including namespaces I do not want to compile as I know they are not needed for my app (some of them even result in compilation failures, like clj-kondo hooks distributed with some libs).
I'm thinking a solution would be to instruct b/compile-clj
to discover namespaces from the entirety of classpath-roots, then make it filter the resulting namespace collection (remove the ones I don't need) before those get into compile.clj.
Unfortunately I don't think this is currently an option. Has anyone run into something like this before? I'm now thinking of using a modified version of compile-clj
but I'd be interested to know whether others have other suggestions.
Or perhaps something telling my why I shouldn't be doing this at all. Thank you.
I don't have an answer but I will point out that plain require
is not thread-safe if you use it heavily at runtime, but requiring-resolve
is thread-safe.
There's an undocumented (and probably private) function called serialized-require
in clojure.core
that was introduced at the same time that is the thread-safe version of require
.
(we use that at work to load namespaces dynamically in one of our apps)
It used to bite us occasionally before we updated to Clojure 1.10 (and switched to serialized-require
).
In case someone also bumps into this and stumbles across this thread, there's now a related clj-kondo issue: https://github.com/clj-kondo/clj-kondo/issues/1685