Fork me on GitHub
#clojurescript
<
2024-01-02
>
cjohansen15:01:05

Is it possible to write a macro that uses a reader conditional? Or, expressed differently: write a macro that emits different code for clj and cljs.

p-himik15:01:22

write a macro that emits different code for clj and cljsYes, (if (:ns &env) (cljs-emitting-fn) (clj-emitting-fn)).

cjohansen15:01:55

thanks!

👍 1
cjohansen21:01:37

I'm benchmarking and optimizing some code. I noticed a spike in runtime (5x) after I added a namespace to a single keyword (e.g. :kw => :mylib/kw). Is this to be expected, or is this more likely a red herring? I have isolated this single change and can repeatedly produce this result. It's very surprising to me.

p-himik21:01:49

It would surprise me too. Have you tried profiling an optimized version of the same code and comparing the results between different keywords? Also, JS VMs can behave in surprising ways when you hit certain limits: https://clojurians.slack.com/archives/C03S1L9DN/p1698696253410799?thread_ts=1698600341.327839&amp;cid=C03S1L9DN

cjohansen21:01:51

I haven't, but that's a good idea, I'll give it a shot.

cjohansen21:01:46

Even stranger: only 1 out of 9 tests in the benchmark exhibit this behavior, and they all "touch" the keyword

cjohansen21:01:04

But I've reproduced it probably 10 times, so pretty sure it's not a fluke

dnolen21:01:23

is this advanced?

cjohansen22:01:30

Out of curiosity from that other thread I re-ran the benchmark with 1.10.597, but got the same results.

cjohansen22:01:29

I was using what I thought was the latest ClojureScript: 1.11.60. In the other thread I see 1.11.121. Github and the clojurescript website have 1.11.60. Where can I find the most up to date version list?

cjohansen22:01:59

This version has the same behavior. Also, my "good" version runs slower on 1.11.121 than 1.11.60 :thinking_face:

p-himik22:01:54

That might be the behavior outlined in the linked thread.

thheller10:01:28

can you share this benchmark? I'd be rather curious to reproduce this. in theory there should be no real measurable difference with a namespaced keyword. as the only difference is the length of the string the browser has to compare (possibly once)

thheller10:01:47

or maybe the benchmark hits a different branch due to the keyword not matching anymore? kinda hard to say without knowing what the benchmark does.

cjohansen11:01:26

I can share it! It's not on Github right now, but will get it there and let you know

cjohansen11:01:14

All the tests pass, so I think behavior is the same. But I agree - must probably be something like that.

cjohansen15:01:46

So... Just to be sure, I tried changing the keyword to another keyword - not with a namespace. And it caused the same problem 😅 So now I'm thinking I need to review my code a little more thoroughly 🙈

cjohansen15:01:13

Holy moly, I just realized - I forgot to update the benchmarking code to use the new keyword :man-facepalming: picard-facepalm :woman-facepalming:

😅 1