babashka-sci-dev

cap10morgan 2022-04-02T15:01:58.065599Z

@borkdude Saw you merged the uberjar support PR. I'm happy to say more about the arg parsing fns refactor if you want me to. Still on my road trip but I get back to real life tonight.

borkdude 2022-04-02T15:03:19.696949Z

Feel free to say more when you get back :) I'll try to get the uberscript stuff in too, so we can prepare for a release hopefully mid next week

👍 1
borkdude 2022-04-02T15:40:32.035479Z

@cap10morgan Did we implement caching for :path pods or not? If you're developing a pod in the JVM it can be pretty slow to load, and loading it an extra time takes a long time... I notice that when running tests :)

borkdude 2022-04-02T15:59:12.221619Z

I noticed this takes pretty long on my machine:

(deftest uberjar-with-pods-test
  (testing "jar contains bb.edn w/ only :pods when bb.edn has :pods"
    (let [tmp-file (java.io.File/createTempFile "uber" ".jar")
          path (.getPath tmp-file)]
      (.deleteOnExit tmp-file)
      (let [config {:paths ["test-resources/babashka/uberjar/src"]
                    :deps '{local/deps {:local/root "test-resources/babashka/uberjar"}}
                    :pods (cond-> '{org.babashka/go-sqlite3 {:version "0.1.0"}}
                            (not (fs/windows?)) (assoc 'pod/test-pod {:path "test-resources/pod"
#_:here->                                                             :cache true}))}]
        (tu/with-config config
          (time (tu/bb nil "uberjar" path "-m" "my.main-pod"))
          (let [bb-edn-entry (get-entry tmp-file "bb.edn")
                bb-edn (-> path JarFile. (.getInputStream bb-edn-entry)
                           InputStreamReader. PushbackReader. edn/read)]
            (is (= #{:pods} (-> bb-edn keys set)))
            (is (= (:pods config) (:pods bb-edn))))
          (is (str/includes? (tu/bb nil "--jar" path) "3")))))))

borkdude 2022-04-02T15:59:20.165699Z

although I set cache true

borkdude 2022-04-02T15:59:24.254919Z

it's because of the local pod

borkdude 2022-04-02T15:59:59.471929Z

I noticed it doesn't get anything from a cache

borkdude 2022-04-02T16:02:24.706239Z

it's weird actually, creating the uberjar takes a long time... why, it doesn't actually have to load the pods at all I guess

borkdude 2022-04-02T16:04:38.996639Z

oh maybe it does load those pods while it shouldn't have to, in the uberjar task

borkdude 2022-04-02T16:05:30.601479Z

but anyway, it seems caching also didn't work, so two issues: • cache for local path does not seem to do anything? • loading of pods for namespaces can be prevented when creating an uberjar

borkdude 2022-04-02T16:18:56.518739Z

Maybe the second one is not important, since we usually do downloading of deps etc too in the first usage of whatever. So it's mostly: why wasn't the cache working I guess

borkdude 2022-04-02T16:19:32.411879Z

Or was that because the test uses a different dir each time? That could be

cap10morgan 2022-04-02T16:28:43.463269Z

Yeah different dir is the likely culprit

cap10morgan 2022-04-02T16:29:22.945819Z

I can work on optimizing that test a bit if you don't beat me to it :)

cap10morgan 2022-04-02T16:29:51.262909Z

Otherwise local pod caching should be enabled when you don't opt out of it

borkdude 2022-04-02T16:32:58.606469Z

Ah right. No, it's fine

cap10morgan 2022-04-02T19:19:52.518859Z

And look into not loading pods when building an uberjar

borkdude 2022-04-02T19:20:15.437139Z

Maybe not so important since when things are cached it won't take time

borkdude 2022-04-02T19:20:45.037819Z

But might be good double checking if the caching is still ok in both registry and local pods

borkdude 2022-04-02T19:21:11.648029Z

There are many things that do not need deps loading and pod caching, but we do it anyway, so I think it's best to leave it

👍 1
borkdude 2022-04-02T16:09:00.356749Z

@highpressurecarsalesm 👋 I saw you were typing. Welcome back :)

Bob B 2022-04-02T16:10:12.185029Z

I'm messing around with the :name metadata for #1223, and it seems like probably the most straightforward way to do it is to add :name in sci's new-var functions (there are a handful of accompanying tweaks in bb to use those functions more). My digging and testing on that has led me to a question that I'd like to confirm to make a better informed decision/proposal about an approach: I think that the intent is that a SciVar's sym field should be a namespace-qualified symbol - is that correct? That does seem to be the case in evaluator, but I think a lot of the copying ones use just a symbol name.

borkdude 2022-04-02T16:11:16.874419Z

Good question...

borkdude 2022-04-02T16:14:03.224189Z

I don't even know why we have sym to be honest. We could get the name from the metadata

borkdude 2022-04-02T16:14:54.140969Z

unless we need to have a proper field for perf reasons

borkdude 2022-04-02T16:16:02.617769Z

Maybe you could get an overview where we need the sym field and how it's typically used, in what functions

borkdude 2022-04-02T16:16:26.781259Z

Then we could decide to either get rid of it and do it via the metadata or fix the field properly

Bob B 2022-04-02T16:27:20.511559Z

from what I've seen, the actual sym field looks like it's primarily (maybe entirely?) used within the deftype

Bob B 2022-04-02T16:31:14.614189Z

... and then other places call getName . I'll do some digging

Bob B 2022-04-02T20:00:34.482859Z

Well, I've got all the sci tests passing with no references to the sym field (all the direct references are in the methods defined in the deftype), so it's doable entirely via metadata (notwithstanding potential performance concerns). My primary concern would be babashka, which, in a couple spots, creates SciVars without metadata (and quite possibly other consumers of Sci that might be calling the SciVar constructor directly instead of going through new-var.

borkdude 2022-04-02T20:14:20.401819Z

Have you found out what potential performance implications might be? When is .getName called, typically? And what happens in the absence of the symbol?

borkdude 2022-04-02T20:14:47.080259Z

One should not create SciVars directly, but always via the sci.core namespace, so I'll accept that breakage

borkdude 2022-04-02T20:15:12.061999Z

(there's still places in bb where I call into .impl namespaces)

Bob B 2022-04-02T21:04:10.491139Z

I only see one call to getName on a SciVar, and that's on an exception path to throw when someone tries to change a built-in var. All the uses of sym appear to be when getting a symbol/string to print a var name.

Bob B 2022-04-02T21:13:25.342999Z

I'm convincing myself more and more that this is a good idea to go after:

before:
(->> (find-ns 'rewrite-clj.zip) ns-publics (take 5))
([child-sexprs #'child-sexprs] [tag #'tag] [insert-space-left #'insert-space-left] [postwalk #'postwalk] [whitespace? #'whitespace?])

after:
(->> (find-ns 'rewrite-clj.zip) ns-publics (take 5))
([child-sexprs #'rewrite-clj.zip/child-sexprs] [tag #'rewrite-clj.zip/tag] [insert-space-left #'rewrite-clj.zip/insert-space-left] [postwalk #'rewrite-clj.zip/postwalk] [whitespace? #'rewrite-clj.zip/whitespace?])
... with assoc'ing :name meta in new-var and removing namespaces from the names getting passed to it, the only outlier I see is *input*, and that should be pretty easy to address

borkdude 2022-04-02T21:14:34.321979Z

nice

borkdude 2022-04-02T19:51:32.121869Z

@cap10morgan I think this is mostly it for uberscript: https://github.com/babashka/babashka/commit/ba6048450fb3d0a8a79df5c6a12b8331ce98132a?w=1

cap10morgan 2022-04-02T21:18:09.466479Z

Great!

borkdude 2022-04-02T19:51:47.053069Z

Need to add a test for it, but works when manually tested.

borkdude 2022-04-02T20:28:01.374469Z

One issue there is that multiple namespaces might load a pod namespace so I got to keep track of those

borkdude 2022-04-02T20:28:34.992769Z

And probably move the load-pods near the top of the script

borkdude 2022-04-02T20:35:17.187199Z

hmm this might be already solved since we dedupe code snippets!

borkdude 2022-04-02T20:35:43.236649Z

yep :)

borkdude 2022-04-02T21:41:32.681239Z

@cap10morgan Merged the uberscript support now. Declarative pods in bb.edn v1 is done I think :)

🎉 1