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.
And, nothing is simple in life. I found myself playing whackamole with the type system.
Might withdraw that PR for now. Not sure how to slide the option in without touching every related js file.
Here's the feature request... https://github.com/facebook/metro/issues/550
@olivergeorge did you try altering the Node memory settings?
It was a long time ago when I tried. Didn’t have success but was left wondering if I was doing something wrong.
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
Thanks I’ll give it a try
Well that worked. A simple build of my app produces a 9mb main.js file.
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.
So thanks!
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
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?
yes
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)
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.
Was your problem with advanced compilation? Do you mind sharing your situation/experience.
Just interested to unpack the problem and understand more
https://gist.github.com/raspasov/b6cf6c59c84bbc3f52a508fbad865ed4
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
yeah, I have something very similar.
My problem was the :simple compilation caused the bundler to crash.
But David's tip about telling node to have a larger max space size means I don't need to use :advanced optimisations
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
@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
(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
Good point. Something to watch for.
Might be also more pronounced on not-so-top-of-the-line devices
Yeah. Should be testable.
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.
Or they could fix it!
For sure, thanks for re-posting that issue, while I doubt it will get noticed, I’ll keep hoping
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
Yeah, adding it is more surface area to test etc... so there's always a downside to adding a feature