clj-kondo

https://github.com/clj-kondo/clj-kondo
dominicm 2020-10-31T15:34:13.269300Z

I'm considering automatically running clj-kondo --parallel --lint in the background on JVM startup. Any reason not to?

borkdude 2020-10-31T15:37:09.269500Z

battery life?

dominicm 2020-10-31T15:39:38.269600Z

@borkdude seems like a non-issue, given that it's only on the rare reboot of the JVM. Does clj-kondo cache at all for that operation?

borkdude 2020-10-31T15:40:13.270Z

clj-kondo always caches when there's a .clj-kondo dir, unless --cache is false

dominicm 2020-10-31T15:41:20.270100Z

@borkdude so the files in jars won't be re-linted?

borkdude 2020-10-31T15:42:13.270800Z

oh you mean like if you call --parallel --lint next time, it will skip the jars? no it doesn't have logic for that

borkdude 2020-10-31T15:42:21.271100Z

there's an issue for this. let me look it up

dominicm 2020-10-31T15:42:47.271200Z

Ah. I'll start with naïve approach, and assume clj-kondo will either fix it later, or I can just cache against the .cpcache :)

borkdude 2020-10-31T15:42:52.271400Z

https://github.com/borkdude/clj-kondo/issues/705

borkdude 2020-10-31T15:43:05.271800Z

there's a bb script in there ;)

borkdude 2020-10-31T15:44:09.272500Z

It's possible to build this logic inside clj-kondo, but then we've got a cache for the cache, which may introduce ... issues?

dominicm 2020-10-31T15:44:31.272600Z

heh, that appears to be from a project I worked on :p.

borkdude 2020-10-31T15:44:50.272800Z

you worked with daniel compton?

borkdude 2020-10-31T15:45:13.273100Z

I thought you worked at JUXT before your current job

dominicm 2020-10-31T15:45:15.273300Z

Hmm, that depends I guess? :) I wouldn't describe this as a cache, the existing thing is more of a "lint history" or "lint record"

dominicm 2020-10-31T15:45:21.273400Z

Daniel worked with JUXT :)

dominicm 2020-10-31T15:45:34.273600Z

So a cache would be a literal cache for that lint history

borkdude 2020-10-31T15:45:39.273700Z

And then he got laid off due to the pandemic or was that another thing?

borkdude 2020-10-31T15:46:03.274200Z

yes, cache is maybe the wrong word, but I also didn't want to call it a database

dominicm 2020-10-31T15:46:31.274300Z

I should clarify. Daniel's company employed JUXT to help out.

borkdude 2020-10-31T15:46:38.274500Z

ah right

dominicm 2020-10-31T15:47:13.274900Z

Hypothetically, clj-kondo could be taught how to resolve namespaces by itself and then it could check the "database" OR just resolve it as a fallback. Hypothetically ofc, there's a bunch of thinking that would need to go into that.

borkdude 2020-10-31T15:47:17.275100Z

I think using the cpcache for this might be a nice idea btw, post it in the issue :)

dominicm 2020-10-31T15:48:03.275200Z

Am I safe-ish to create files in .clj-kondo/cache? If so, I'll use the cpcache as my approach.

borkdude 2020-10-31T15:48:39.275700Z

yeah, you can put anything in the .cache dir, clj-kondo won't punish you

borkdude 2020-10-31T15:49:31.276200Z

you could even have a global cache I guess of linted jars

borkdude 2020-10-31T15:49:47.276500Z

like ~/.clj-kondo/.cache/foo.jar/....

borkdude 2020-10-31T15:50:04.276800Z

and when clj-kondo lints the jar it will just copy it from there or something

dominicm 2020-10-31T15:50:24.276900Z

I might encourage a symlink if possible. Learning from the npm->yarn transition!

borkdude 2020-10-31T15:50:49.277200Z

yeah, or clj-kondo will just do lookups to a global cache as a fallback

borkdude 2020-10-31T15:51:03.277400Z

meh

borkdude 2020-10-31T15:51:15.277800Z

I can already feel the github issues coming ;)

borkdude 2020-10-31T15:51:43.278200Z

but it could be nice. lint your .m2 dir once, profit many times

dominicm 2020-10-31T15:51:56.278300Z

fwiw, I think clj is going to pursue a similar idea for AOT.

dominicm 2020-10-31T15:52:13.278400Z

https://clojure.org/guides/dev_startup_time automating this process

dominicm 2020-10-31T15:52:20.278500Z

or maybe for prod, not sure. Alex hinted at it.

dominicm 2020-10-31T15:52:38.278600Z

Immutable deps make this a lot easier

borkdude 2020-10-31T15:52:51.278800Z

yeah

borkdude 2020-10-31T15:54:05.279200Z

the cache is also keyed on .clj-kondo version btw, so updates to clj-kondo would invalidate it

dominicm 2020-10-31T15:54:13.279300Z

Makes sense.

dominicm 2020-10-31T15:54:43.279500Z

Btw, if any other tricks like this come to mind that a project could experiment with, let me know. I'm working on a place for hacks like this to be tested in a way that wouldn't require long-term commitments on your part.

borkdude 2020-10-31T15:57:03.279800Z

other tricks can be posted in the issue I guess?

dominicm 2020-10-31T16:00:22.279900Z

I meant unrelated to caching :) Others similar to auto-caching on JVM startup

borkdude 2020-10-31T16:01:22.280200Z

ah right.

dominicm 2020-10-31T16:09:23.280300Z

❯ time clj-kondo --parallel --lint  /home/overfl0w/.m2/repository/refactor-nrepl/refactor-nrepl/2.5.0/refactor-nrepl-2.5.0.jar
<snip>
clj-kondo --parallel --lint   4.77s user 0.35s system 99% cpu 5.163 total
❯ time clj-kondo --parallel --lint  /home/overfl0w/.m2/repository/cider/cider-nrepl/0.25.3/cider-nrepl-0.25.3.jar
clj-kondo --parallel --lint   7.82s user 0.38s system 99% cpu 8.272 total
That's... impressively slow :p

dominicm 2020-10-31T16:11:00.280600Z

I suspect that's mostly my machine being old, but also the size of these two jars is probably disproportionate. They contain embedded tools reader copies, etc.

dominicm 2020-10-31T16:11:16.280700Z

Might be worth doing a content cache I guess, not sure if you do already

borkdude 2020-10-31T16:11:45.280900Z

you mean, like hashing the source?

borkdude 2020-10-31T16:12:07.281200Z

clj-kondo doesn't use any of this, it just re-lints every time you feed it something

borkdude 2020-10-31T16:18:41.281500Z

@dominicm btw, the JVM may be a tad faster due to JIT

borkdude 2020-10-31T16:18:55.281900Z

so you could also include clj-kondo as a JVM dep

dominicm 2020-10-31T17:00:01.282Z

Hmm, don't think that's useful necessarily here. As if the user doesn't have clj-kondo installed, then the cache isn't much use to them.

dominicm 2020-10-31T17:00:05.282100Z

Will ponder.

borkdude 2020-10-31T17:05:58.282600Z

ok