Fork me on GitHub
#clojurescript
<
2023-03-12
>
hifumi12302:03:15

Since top-level data structures do not undergo DCE, what would be a reasonable compromise between optimizing bundle size and speed? Obviously top-level data structures can be reorganized into a function constantly returning the data to save on bundle size, but this also has negative performance impacts, doesn’t it? EDIT: I guess we could rely on Google Closure being able to statically infer function calls and paste data structures directly into functions using them. No idea if it is also capable of caching this constant value across functions calls, however.

thheller06:03:06

delay is an option. (def that-thing (delay {:big ["structure"]})), only downside is that you need @that-thing, but that is reasonable

thheller06:03:19

what kind of top level data structure are you talking about though? it can be much much better to keep the structure out of the code entirely. instead loading an .edn or .json or whatever file on startup.

thheller06:03:28

lets you update the data without having to recompile too

hifumi12306:03:21

I’m looking at a library that has a large map. Putting the map into a function reduces bundle size significantly.

thheller06:03:59

ok, then delay is best if it gets called multiple times

👍 2
p-himik11:03:14

Why is delay better than a function, assuming that the data is static? Derefing a delay is a process that's much more complex than calling a function.

thheller11:03:03

it is not? a function re-creates the data structure every time you call it. a delay creates it once.

thheller11:03:31

after that a deref is a protocol function call, so basically a regular function call. nothing more complex about it.

borkdude20:03:21

SCI also has a large top level map. Didn't know about this issue. Will try delay

thheller20:03:40

I assume SCI uses it? DCE is not an issue then

borkdude20:03:09

yes, it uses it heavily

borkdude20:03:21

it's a top level map with (most of) core's functions

borkdude20:03:44

and it's by design that the keys/vals in that map aren't DCEd

p-himik20:03:17

> a function re-creates the data structure every time you call it Huh. That's not the case in CLJ. Why doesn't CLJS cache it? Is there a possibility for enhancement? > after that a deref is a protocol function call Ah, once again I'm trying to apply my knowledge of CLJ to CLJS. In CLJ, deref uses instance?.

thheller20:03:08

thats also basically free

thheller20:03:07

I believe there is still an open issue about more static data caching yes

thheller20:03:59

kinda tough to find the right balance, some things are DCE'd after all. don't want to lose that