Fork me on GitHub
#clojure
<
2019-08-22
>
favila03:08:34

Is there an easy way to determine how much time each namespace is contributing to a require? I have a require that is taking a long time and I suspect some transitive require has a slow top-level form

Alex Miller (Clojure team)03:08:24

you can add :verbose to a top-level require and it will print for each one it loads transitively

Alex Miller (Clojure team)03:08:33

might be able to just spot it from watching

Alex Miller (Clojure team)03:08:44

is core.async in there? if so, that's it :)

favila03:08:29

Thanks! Will try in the morning. I’m not sure if it’s in there

Silenced Ego06:08:54

How does clojure handle dynamically extending types to implement new protocols? This is impossible to do in java. Does it compile somehow to branching code that emulates the behavior, or does the JVM have dynamic type extension built in?

schmee07:08:44

the first one, IIRC, but it uses a lot of perf optimizations

andy.fingerhut07:08:28

I do not have this process terribly well understood myself, but roughly there is a map for each protocol (and perhaps each protocol function) that you define, and this contains a cache of the correct function to call based upon the class of the first parameter. These get updated when extend-protocol and/or extend-type are called (perhaps one or two others I am forgetting). There are special (but reasonably common) cases where the Java method call lookup machinery is enough, e.g. if you define the protocol function implementations when you call deftype.

Alex Miller (Clojure team)12:08:07

That started right - a protocol is a map of types to function impls. The caching happens per call-site though, not in the protocol

borkdude13:08:20

what's a good way to check if something is amenable to adding metadata?

user> (instance? clojure.lang.IObj list)
true
user> (with-meta list {:a 1})
UnsupportedOperationException   clojure.lang.PersistentList$Primordial.withMeta (PersistentList.java:58)

bronsa13:08:25

instance? IObj is the correct way

bronsa13:08:57

list is the odd one out, but I mean nothing prevents you from (reify clojure.lang.IObj) aswell

borkdude13:08:15

no, I want to reject this, but this method doesn't work

bronsa13:08:27

there's no static way to go about it

borkdude13:08:34

so try / catch... ?

bronsa13:08:42

(reify clojure.lang.IObj (withMeta [_] (throw (Exception.)))

bronsa13:08:47

how can you figure out this throws

bronsa13:08:51

yeah try catch I guess

Alex Miller (Clojure team)13:08:56

in your code above, is list literally the list function? or is list bound to an actual list instance?

borkdude14:08:05

it's literally the list function

valerauko14:08:46

is there a database that works like clojure's data structures? (keeping track only of the differences)

Alex Miller (Clojure team)14:08:07

(to some degree, really more complicated than that)

Juliano Pereira Lima16:08:56

what is the best way to receive a file via stdin in a clojure console application using leininger?

cupello17:08:01

Hi! Anyone here using newrelic with clojure?

seancorfield18:08:22

@lucelios Yes, we use New Relic heavily in production with Clojure backend processes. Do you have a specific question?

cupello19:08:09

Hi Sean! We are having difficulty with cross-application traces... We use aleph.http for requests and New Relic headers are not being added automatically. Did you have to experience something like that?

seancorfield20:08:00

New Relic's support for non-mainstream HTTP clients and servers is less than stellar. We started out with http-kit as our server and after various tweaks and working with NR support for a while, we gave up and switched to Jetty instead (and, even then, we had to test a few versions to establish which ones they fully supported).

seancorfield20:08:19

For requests, we use a mixture of clj-http and http-kit (client). Both of those seem to work fine with distributed traces and tracking external services -- but it's entirely possible NR doesn't know how to track HTTP requests made with Aleph (and so it doesn't add headers automatically).

cupello19:08:10

hmmm I see.. Do you know a good way of adding X-NewRelic-App-Data header into the response?

seancorfield19:08:42

I'd have to know quite a bit more about your app -- how the services are built and how they're called, since you're going to need to do this manually. I've never used Aleph.

Silenced Ego23:08:52

Does a Go implementation of Clojure make sense given they both use CSP, and if that's possible could that raise clojure's popularity?

seancorfield23:08:44

@thomasskinner76 I doubt that a Go implementation would be anywhere near as widely used as the current JVM-based version...

noisesmith23:08:10

clojure would perform very poorly with go's vm, clojure really demands a lot from the GC

jaihindhreddy04:08:03

Is Go's GC far behind the JVM's? I'd greatly appreciate any resources for me to learn more about this.

noisesmith16:08:10

it's a different style of GC, and it doesn't handle the specific case of massive amounts of short lived objects the way the JVM does

noisesmith16:08:09

for idiomatic Go code, it works very well if tuned correctly for your domain, but it doesn't really match the way idiomatic clojure code uses local immutable values that quickly leave scope

noisesmith16:08:42

I mean, go code is usually faster than java, but that's more due to mechanical sympathy than advanced vm tech

💯 4
noisesmith16:08:28

and clojure opts out from that kind of mechanical sympathy - trading it for the semantic guarantees of immutables

seancorfield23:08:43

(and core.async implements "CSP" by rewriting code at the Clojure level so a "Go implementation of Clojure" wouldn't address that)

noisesmith23:08:27

in fact if CSP was in clojure's core core.async would probably be less awkward - not that we should do that or anything

Alex Miller (Clojure team)23:08:45

We have actually talked about making the analysis parts of the compiler available in a way such that core.async could use it rather than reimplementing it in a macro, which would also make it a lot less awkward

Alex Miller (Clojure team)23:08:04

But prob not something happening soon

noisesmith00:08:18

that would make core.async much nicer

Silenced Ego23:08:26

that's interesting. What does Go's VM lack for clojure that would be needed? It somehow has better GC?

noisesmith23:08:53

Go has a mediocre gc, compared to the jvm - specifically in terms of performance. Clojure's usage of immutable data creates a lot of short lived garbage.

hiredman23:08:54

supposedly light weight threads as a vm feature are coming to the jvm, but I will believe it when I can deploy it

💯 4
hiredman23:08:27

go is also largely a static runtime, which makes using a language with dynamic code loading annoying

👍 4
Silenced Ego23:08:25

Oh I see. So the performance of Go which is generally supposed to be very good, is partially only that way because people use mutable state, instead of programming functionally. Is that right @noisesmith ?

hiredman23:08:43

(also concurrent ml's model of synchronizing on events is a super set of go's channels, and way cool)

noisesmith23:08:40

@thomasskinner76 it might be more straightforward to say that the jvm is unique among vms (or relatively unique) in having a short term garbage collector that allows operations on immutable data structures to be performant

hiredman23:08:00

I have an abandoned lisp that compiled to go source code that I was working on because I was interested in go's concurrency primitives, which I stopped doing work on around when core.async was released