Fork me on GitHub
#rum
<
2017-03-25
>
jrychter12:03:20

A generous sprinkling of {} in my rum app has just saved me 83.8kB in code size (4.2kB compressed). That's pretty impressive. I'm thinking about updating the Rum docs.

rauh12:03:48

@jrychter You mean in hiccup? [:div {} ...]?

jrychter12:03:42

@rauh: yes. My coworker gave me that hint. Turns out the compiler is too trigger-happy with code inlining and in some cases you get exponential increase (strings included 4 times).

rauh12:03:03

Yeah I stripped the sablono interpreter completely, either it compiles into React.createElement calls or it will give me an error.

rauh12:03:38

Saved a bunch of kb and allows me to be more flexible with returning vectors of react elements

jrychter12:03:17

What's the downside?

rauh12:03:46

Also see:

rauh12:03:09

Well the downside is you have to manually add some (html ...) macro calls to your code or it won't work

rauh12:03:34

so (mapv (fn[item] (html [:div ....]))) instead of just (fn[..] [:div ...])

jrychter12:03:39

Oh that's interesting — I didn't know there is a disadvantage to using for

rauh12:03:27

I also have my own defc that creates the component lazily (`delay`). Saves 100ms on startup time for me

rauh12:03:49

So with my hacks, you can do

(if foo?
  [[:span {} "one"]
   [:span {} "two"]]
  [:div "else"])

jrychter12:03:35

I wonder about replacing for with mapv though — should I use mapv or map? Does anybody care? Is one better/faster?

rauh12:03:18

I have a macro that just pushes things into a js array. Works fine.

rauh12:03:26

Let me gist it

jrychter12:03:47

well, I don't want to go overboard with these optimizations: code readability is very important for me

jrychter12:03:11

But I guess in this case it would be fine to replace the for or mapv with something that directly creates a JavaScript array, I'm not going to do anything else with it anyway.

rauh12:03:59

Well IMO for is much more readable than mapv (which also needs html since sablono can't walk into functions)

jrychter12:03:32

Yes, that's why I've been using it. But replacing it with mapv produces significant savings (I've just checked).

jrychter12:03:01

Oh, these are nice — thanks! I think I'll adopt them.

rauh12:03:01

Yeah, I don't use for ever (I wrote the "optimizations" page on sablono). It's nuts the code it produces

jrychter12:03:52

I do have to be careful, though… More and more of my code is being migrated to .cljc files, as I'm doing server-side rendering for many things.

jrychter13:03:16

Total code size reduction for today (not using your macros yet): 115.6kB, or 11kB gzipped. That's 5.5% of the total.

martinklepsch15:03:16

@rauh @jrychter have you guys seen this? https://github.com/tonsky/rum/issues/128 — was quite surprised to learn components aren’t properly DCE’d

jrychter15:03:32

Yes, this has been opened by precisely the coworker I mentioned :-) He alerted me to the '{}' issue.

martinklepsch15:03:57

Ha! This stuff is tricky, you really need to watch what you’re doing...

rauh18:03:26

@martinklepsch I have, I played around with it for like 30min this morning. No clue why it's not DCE'd. 😕