r/Clojure • u/luciodale • Oct 21 '21
I’ve recently written an article on ClojureScript and performance. Hope it’s helpful :)
https://www.juxt.pro/blog/clojurescript-app-performance4
u/arthurbarroso Oct 21 '21
Amazing article, thank you for writing this!. Did not know type hinting could improve the generated code. Also loved the part about document.hidden.
1
3
u/didibus Oct 22 '21
Reagent components can be expensive to render frequently because hiccup uses Clojure vectors, which are immutable data structures that carry a relatively high garbage collection cost
I don't think there's really any reason why Hiccup uses vectors correct? So one could imagine a data-reader that would build it up into a different maybe more lightweight GC friendly structure? I wonder if that be enough to provide considerable speedups.
6
u/roman01la Oct 24 '21 edited Oct 24 '21
we are actually experimenting with tagged Hiccup at Pitch, something like #el [:div], still looks like hiccup but actually compiles into plain react calls
Since it’s compiled, it’s no longer actual Hiccup as we know it, but more of a templating language similar to JSX in a sense that it is static, can’t be constructed at runtime. It’s a fair trade off once, not only for performance, but also code readability.
3
u/lilactown Oct 25 '21
do you think it'll be generic enough to work with helix and reagent? I'm sure people would love it
1
u/jayceedenton Oct 24 '21
This would be fantastic. Are you close to publishing this as something for general use?
Helix (mentioned in the blog post) replaces hiccup syntax with invocation of macros, which IMO is a bit less readable than hiccup. If we could keep the hiccup syntax but avoid the runtime parsing, this would be the best of both worlds.
1
3
1
u/dustingetz Oct 21 '21
hiccup is the vietnam of clojure
2
u/luciodale Oct 21 '21
Well, hiccup can be very nice to work with and does just fine in several contexts. It’s just important to know its pitfalls and when’s better to go for something different :)
5
u/dustingetz Oct 21 '21
Sorry - i agree with you. Hiccup feels very cute to write and Reagent has proven capable for a wide range of apps – in fact it has made a wide range of apps feel easy. However as your article states, above a certain threshold of demand or rigor it starts to fall apart as reactive deref tracking is not algebraic and the performance is broken by default in invisible ways. It's a good article. I lost a year of my life trying to muscle reagent. We wrote a reactjs replacement powered by https://github.com/leonoel/missionary this summer in a quarter (no Reactjs dependency). We are pretty excited about it.
1
1
-10
Oct 22 '21 edited Oct 22 '21
So much trouble just to avoid writing Javascript...
"Hey, look at the solutions I found for the problems I created but shouldn't have!"
1
u/luciodale Oct 22 '21
One could use the same quote to describe the relation between TypeScript and JavaScript ;)
-5
Oct 22 '21
Nope. TS doesn't bring the performance issues cljs introduces. But that you didn't even realize my comment was about performance just shows how clueless and mediocre as a programmer you are.
3
4
u/FORCE4760 Oct 23 '21
You know that performance is not everything right? There are cases were performance matters a lot, but in others just let everyone use the language/paradigm that they like.
Any language that compiles to JS has its own benefits and pitfalls (JS has them too) there are cases where cljs would be better than TS and cases where it would not
4
u/Levaiel Oct 21 '21
Great in-depth yet accessible article !