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.
What's jscomp and how would using es7 improve the situation?
@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 😛
I also tried shrinking the code produced by those fns directly in the compiler but its not easy. lots of things to balance.
AFAIK jscomp is compatibility layer for older versions of JavaScript. You can remove all js comp by switching to different target version.
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.
so it sometimes generates weirdly long names but in true :advanced
would be real short like a,b,c
etc
but this is ONLY :pseudo-names
and has nothing to do with transpiling/polyfilling/etc whatsoever
somewhat easier to look at the original source since it isn't rewritten much by :advanced
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!
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 😛
@ikitommi thats the :advanced
version pretty printed
the biggest reason why things get so large is IFn
support which makes things rather tricky in some places
eg. all the places a.a ? a.a(g) : a.call(null, g);
that could just be a(g)
without IFn
how did you get the pretty printed advanced version out? would it possible to include per-var sizes into shadow reports?
the generated code with pseudo-names
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.
One of the reasons I stopped using Specter in CLJS - it has a lot of such functions.
would be great to have the table of sizes, including dependencies and maybe even a linter/tool on top of those.
I see a lot of jscomp. Try targeting different feature set like es7 and check the results.
well, that as a surprise 😮
cljs.user=> (identical? :random-keyword :random-keyword)
false
cljs.user=> (= :random-keyword :random-keyword)
true
(in clj
the first one returns true
)
aha: https://ask.clojure.org/index.php/8539/why-are-keywords-not-cached-and-interned-in-clojurescript
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
if i go to repl and call (re-render)
after clicking the button, the call history section does show the new content