Fork me on GitHub
Oliver George02:04:36

Hi All, I'm bolding proposing a PR to metro to allow the constantFoldingPlugin to be disabled. This matters if you need to use advanced optimisation on your releases. For example, my app is too big for the metro bundler without it and throws out of memory errors.

Oliver George03:04:04

And, nothing is simple in life. I found myself playing whackamole with the type system.

Oliver George03:04:38

Might withdraw that PR for now. Not sure how to slide the option in without touching every related js file.


@olivergeorge did you try altering the Node memory settings?

Oliver George11:04:50

It was a long time ago when I tried. Didn’t have success but was left wondering if I was doing something wrong.

Oliver George11:04:29

Can you point me at an example and I’ll try again


--max-old-space-size and maybe set that to something relatively large like 4-8gb

Oliver George11:04:14

Thanks I’ll give it a try

Oliver George11:04:40

Well that worked. A simple build of my app produces a 9mb main.js file.

Oliver George11:04:10

My baseline was running node /usr/local/bin/react-native start which throws the GC error. Then I tried node --max-old-space-size=8192 /usr/local/bin/react-native start and it loaded successfully.

Oliver George11:04:41

Is that how you'd have added the flag? I'm wondering how to ensure that is set when I'm bundling for an iOS release.


export NODE_OPTIONS=--max_old_space_size=4096

Oliver George11:04:48

Brilliant. Thanks.


Having an initial play with Krell. What's the mechanism for dragging in image assets?


works just like JavaScript


make a path relative to your file


Thanks. Do you need to js/require?


Hmm, now completely broken with "SyntaxError: Unexpected token ':'"


What's the most effective way to trace these errors from the simulator back to the code?


@admarrs sorry, it would be easier if you just paste what your asset require looks like


Working this morning. Finished last night with the Krell_repl.js error outlined above then this morning cleared target and .cpcahe rebuilt and it works as expected. Thanks for your help.


adding a new pass to Krell to pick up js/require that loads libs not just assets


should help w/ migration from re-natal


@olivergeorge Yes, this is so much needed (disabling constantFoldingPlugin)

Oliver George22:04:07

Hi @raspasov - With the workaround David pointed out you might find it's not critical anymore. From my understanding :simple compilation should be suitable for react native since we're rarely worried about code size and can rely on the VM for optimisations.

Oliver George22:04:13

Was your problem with advanced compilation? Do you mind sharing your situation/experience.

Oliver George22:04:27

Just interested to unpack the problem and understand more


I use this…


It’s not critical, but it has been a problem for years with metro with :advanced compilations


I wrote this script that patches the node_modules/metro/src/JSTransformer/worker.js file

Oliver George22:04:14

yeah, I have something very similar.

Oliver George22:04:30

My problem was the :simple compilation caused the bundler to crash.

Oliver George22:04:15

But David's tip about telling node to have a larger max space size means I don't need to use :advanced optimisations

Oliver George22:04:30

Can you see a downside to that?


That can work, but I prefer :advanced, :simple can grow very large as your project grows and you add more and more libraries


I am not sure how much this constantFoldingPlugin really saves on the average RN project in terms of code size

Oliver George23:04:39

@raspasov size: yep, mine is 9mb off 40k lines of clojurescript. I guess the question is whether that causes real problems or just "feels" heavy compared to the sorts of filesizes we're used to being suspicious of

Oliver George23:04:41

(e.g. my 9mb gzips down to 900k so I imagine the app download is still small)


@olivergeorge are the app downloads gzipped? I am not sure


They might be, I just don’t know


The other thing to watch for is app startup time, larger files can have somewhat of a noticeable difference (a few seconds) as far as I recall… I might be wrong, that was a few years ago when I last tested this

Oliver George23:04:40

Good point. Something to watch for.


Might be also more pronounced on not-so-top-of-the-line devices

Oliver George23:04:00

Yeah. Should be testable.

Oliver George23:04:30

But you make a good point. Even if most people don't hit a performance issue it's going to be helpful to some to have an option to disable constant folding.

Oliver George23:04:09

Or they could fix it!


For sure, thanks for re-posting that issue, while I doubt it will get noticed, I’ll keep hoping

👍 4

I assume it’s just not a big issue for them since it only affects a small subset of RN developers who use Google Closure

Oliver George23:04:41

Yeah, adding it is more surface area to test etc... so there's always a downside to adding a feature