Fork me on GitHub
#clojurescript
<
2020-09-25
>
ikitommi06:09:21

hi. I was optimizing bundle size for a small (<10kb) library, noticed that use of some-fn added 2kb size gzipped. not 100% sure about the measurement accuracy, but… i’ts a huge function: https://github.com/clojure/clojurescript/blob/154b19a40e33fb9285bd5c16bc96ec0ab88c4261/src/main/cljs/cljs/core.cljs#L4678-L4715. Same seems to apply for every-pred and many others. Is there any list of js-size for core functions? these are usually easy to unroll for spesific cases.

ikitommi06:09:03

the generated code with pseudo-names

p-himik06:09:26

I don't know of a list of such functions. But I'm pretty sure that any function with similar multiarity implementation will be compiled into a similar monster.

p-himik06:09:26

One of the reasons I stopped using Specter in CLJS - it has a lot of such functions.

ikitommi06:09:52

would be great to have the table of sizes, including dependencies and maybe even a linter/tool on top of those.

3
Karol Wójcik06:09:21

I see a lot of jscomp. Try targeting different feature set like es7 and check the results.

p-himik07:09:02

What's jscomp and how would using es7 improve the situation?

thheller07:09:40

@U055NJ5CC basically all multi-artiy + variadic fns generate this much code. in shadow-cljs I added a helper to find big code forms. :compiler-options {:form-size-threshold 25000} which will make the compiler warn if a given form produces more than 25kb JS. not very useful given that it is before :advanced but I've used it in the past to find forms expanding to over 100kb JS 😛

thheller07:09:00

I also tried shrinking the code produced by those fns directly in the compiler but its not easy. lots of things to balance.

Karol Wójcik07:09:08

AFAIK jscomp is compatibility layer for older versions of JavaScript. You can remove all js comp by switching to different target version.

thheller07:09:16

note that the code above is :pseudo-names code. the jscomp references are just there for "pseudo-name" reasons where the compiler picks a name that is close to the original but still renamed.

thheller07:09:53

so it sometimes generates weirdly long names but in true :advanced would be real short like a,b,c etc

thheller07:09:20

but this is ONLY :pseudo-names and has nothing to do with transpiling/polyfilling/etc whatsoever

thheller07:09:24

somewhat easier to look at the original source since it isn't rewritten much by :advanced

ikitommi07:09:16

yes, the 2kb was after advanced, just couldn't find where the some-fn started & ended, so pasted the pseudo-names code. :form-size-threshold sounds just what I need now, thanks @U05224H0W!

👍 3
thheller07:09:53

don't make it too small or it will find a lot of them. it also has been a couple years since I used it so it might not even work anymore 😛

thheller07:09:05

@U055NJ5CC thats the :advanced version pretty printed

thheller07:09:24

the biggest reason why things get so large is IFn support which makes things rather tricky in some places

thheller07:09:15

eg. all the places a.a ? a.a(g) : a.call(null, g); that could just be a(g) without IFn

ikitommi07:09:49

how did you get the pretty printed advanced version out? would it possible to include per-var sizes into shadow reports?

Jeff Evans18:09:49

well, that as a surprise 😮

cljs.user=> (identical? :random-keyword :random-keyword)
false
cljs.user=> (= :random-keyword :random-keyword)
true

Jeff Evans18:09:00

(in clj the first one returns true)

ozzloy23:09:50

when i update my app atom, the page does not render the new state. what am i doing wrong here? here's a minimized demo code https://gitlab.com/ozzloy/b1ng0/-/tree/minimal-atom-wip

ozzloy23:09:45

if i go to repl and call (re-render) after clicking the button, the call history section does show the new content