clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
ikitommi 2020-09-25T06:06:21.029500Z

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.

p-himik 2020-09-25T07:08:02.032600Z

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

thheller 2020-09-25T07:13:40.032800Z

@ikitommi 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 😛

thheller 2020-09-25T07:15:00.033Z

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ójcik 2020-09-25T07:32:08.036100Z

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

thheller 2020-09-25T07:33:16.036300Z

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.

thheller 2020-09-25T07:33:53.036500Z

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

thheller 2020-09-25T07:34:20.036700Z

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

thheller 2020-09-25T07:35:24.036900Z

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

thheller 2020-09-25T07:35:47.037100Z

ikitommi 2020-09-25T07:36:16.037500Z

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 @thheller!

👍 1
thheller 2020-09-25T07:37:53.037800Z

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 😛

thheller 2020-09-25T07:44:05.038Z

@ikitommi thats the :advanced version pretty printed

thheller 2020-09-25T07:45:24.038400Z

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

thheller 2020-09-25T07:46:15.038600Z

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

ikitommi 2020-09-25T07:56:49.038800Z

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

ikitommi 2020-09-25T06:07:46.029800Z

ikitommi 2020-09-25T06:08:03.030200Z

the generated code with pseudo-names

p-himik 2020-09-25T06:09:26.030400Z

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-himik 2020-09-25T06:10:26.030600Z

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

ikitommi 2020-09-25T06:36:52.030800Z

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

➕ 1
Karol Wójcik 2020-09-25T06:59:21.032400Z

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

2020-09-25T18:29:49.041Z

well, that as a surprise 😮

cljs.user=&gt; (identical? :random-keyword :random-keyword)
false
cljs.user=&gt; (= :random-keyword :random-keyword)
true

2020-09-25T18:30:00.041400Z

(in clj the first one returns true)

ozzloy 2020-09-25T23:09:50.043600Z

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

ozzloy 2020-09-25T23:10:45.044700Z

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