Fork me on GitHub
#shadow-cljs
<
2022-07-12
>
thheller07:07:56

FWIW I changed it so idents are their own type. wanted to do that for a while, so I guess it was time before people actually start using this 😉

borkdude09:07:07

It's probably not supported right now, but could it theoretically be supported that the build report shows the function size too, so I know where to look if I want to optimize something for size?

thheller09:07:12

function size?

thheller09:07:11

the way I typically look for thing for optimize is running a release build with --pseudo-names and then going over the generating sources. it is fairly easy to identify large chunks and associating them with their respective sources

thheller09:07:21

takes a bit of practice

thheller09:07:25

a test build with :modules may also help. so :modules {:code {:entries [cljs.core]} :target {:entries [the.namespace] :depends-on #{:core}}

thheller09:07:42

so target.js will only contain code from the namespaces I'm trying to tweak

borkdude09:07:11

My issue is that in SCI I'm re-implementing macros as normal functions: e.g.:

(defn foo [_ _ body] `(do ~@body)) 
Contrived example: ^ But the backtick generates a lot of code that could be more optimal/smaller. So I'm going through various macros now to manually rewrite it to get rid of the backtick. This is where my question comes from. Yeah, inspecting the generated code already helps, this is how I first learned about this bloat :)

thheller09:07:55

well backtick itself doesn't generate a lot of code

thheller09:07:11

the unintepreted datastructures do

thheller09:07:41

so new cljs.core.List([new cljs.core.Symbol("do", ... and so on

thheller09:07:56

dunno how you'd shrink that

borkdude09:07:43

This is what you see in the outputted JS:

user=> '`(do ~@body)
(clojure.core/seq (clojure.core/concat (clojure.core/list (quote do)) body))
(the JS equivalent of those) Manually writing that as:
user=> '(list* 'do body)
(list* (quote do) body)
yields smaller code. I notice this by re-running the build report.

thheller09:07:00

hmm but those are not equivalent?

thheller09:07:36

I mean yes, the concat/seq stuff is not ideal but in the end that is only a small part no?

borkdude09:07:00

It gets way worse when your macro isn't trivial like the above

borkdude09:07:28

Normally in CLJS this isn't a problem, since the JVM deals with this boilerplate at compile time - only if you pull the macro to runtime

thheller09:07:44

I mean yeah I get that. constructing big nested datastructures yields a lot of code

thheller09:07:36

hmm dunno how you'd optimize that