-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Out of memory or out of time when compiling large JS files #111
Comments
Happy new year! Any update on this? |
Hey @jeaye ! Happy new year and apologies for the delay. The timeout on transformations was indeed [removed some time ago]( (d4dcd4c), so from metro v0.21.0 there is no maximum time to transform a file. Out of curiosity, can you provide more details about the file that you're trying to compile? How big is it? Why is it so big? Metro is heavily optimized to build bundles with a really big amount of small files, but cannot run that fast when trying to compile a small amount of huge files (it's impossible to parallelize, the caching system is not efficient, etc(. |
@rafeca In production, my As linked above, this issue is affect basically everyone using ClojureScript with RN, likely due to the CLJS stdlib and everything else included in the compiled file. Note, this is going through Google Closure, so it's not like there's a lot of waste here which we can trim down; all dead code is removed and all remaining code is optimized and minified. Closing this issue because the timeout is removed is ok, but, really, waiting over 5 minutes to transform these files is pretty awful. Trying to do this with a non-production build (which doesn't have Google Closure optimizations applied) is a fool's errand, since it'll take more like 30 minutes, if it doesn't run out of memory before that. |
@jeaye : thanks for the explanation! it makes complete sense 😄 In this case, since your Anyways, this flow that you describe is still going to be slow and painful in development mode (as you describe, every time you do a change you have to recompile the whole bundle from clojurescript to javascript, and then metro will see the modified file so it won't be able to leverage its cache and will do the whole bundling). If possible, a much better flow would be to integrate the clojurescript compiler with metro, so metro would call the compiler on a per-file basis and you will benefit from the speed/parallelization/caching of metro. I'm not familiar with clojurescript and its compiler, so I don't know if it can even work on a per-file basis, But if it can the integration should not be super-complex:
Let me know if this helps |
@rafeca Thanks for the detailed reply. The ignoring approach was mentioned in the first referenced issue here, but it leads to other issues. When I try it in my production build, rather than my test case repository, I run into issues because my JS actually needs to be transformed. That is, I have some NPM dependencies using newer JS features which need to be transformed for RN to consume them. The failure looks something like this:
|
@jeaye it seems that there're other files in dependencies called Have you tried refining the regexp used in the |
@rafeca That's a very good idea; the babel docs don't mention anything of the sort, as far as limiting matches to the top-level directory. I've tried various patterns, from My research into how babel looks this up seems like any JS file within |
Why is this issue closed? I have a json file with 17.4MB. "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory" |
@roesneb It certainly shouldn't be closed. It was ignored when it was reported, multiple times, in the react native repo, while people suggested it be brought up here. Now that it's brought up here, it's promptly closed and no workarounds are available (for people using ClojureScript). For your problem, you might try ignoring that JSON file using your babelrc. Alas, if it has a common name, then all JSONs with that name will be ignored, which is the last problem about which I asked @rafeca. |
@jeaye i've tried the ignoring option already, without success. I could split up my JSON in multiple files but I don't think that should be the way to do it. |
Any news on this "not solved" issue ? |
@VincentFTS If this is possible:
Then the problem can be resolved for ClojureScript users. No documentation I've found has shown it to be possible though. Instead, renaming your app's |
The problem is that the "big file" is a javascript file that uses flow, it permits to check the format of a big table. |
Hello @jeaye Did you end up solving this issue for CLJS? Our iOS build is functioning fine, but our android build not so well. On a previous version of react native, We did all sorts of monkey patching to make the transformers not run for our ClojureScript files it was horrible, but it worked. After upgrading to the latest RN we were hoping to avoid the money patching if possible. |
@ChadHarrisVerr Nope, this is still very much an issue. metro doesn't handle large files well and has a non-linear time growth with respect to file size. So far, there's been no official way to speed things up and this ticket, just like many others here and in the react-native repo, has been closed with little help (read the full discussion here to understand more, if you haven't). I have documented my current workaround here: https://github.com/cljsrn/cljsrn-org/wiki/Avoiding-Metro-timeouts In short, I patch metro to not give up after several minutes of transforming and I just wait a long time for my prod builds. As a result of this, I also can't reasonably use something like jest for testing, since it wants a bundled package as well. |
In order to fix this, you'll need to use a custom Metro transformer to skip loading the entire compiled Clojurescript AST, and also load its dependencies properly. I've documented how to do it here: https://www.arctype.co/blog/fixing-react-native-compiler-clojurescript-timeouts cc @bonlemuel @ChadHarrisVerr |
Hi @sundbry, The article from arctype is great and all :P but i can't get it to work... i keep getting Can you help with that? (btw i'm trying to solve a different problem, where the bundler is eating some functions from clojurescript core causing a wierd error, and no, it's not an externs thing :P) |
@boogie666 Metro changed the interface here in v0.47.0: Try reverting your metro to 0.45.4 |
@sundbry Lifesaver :* thx a lot :* |
FYI including @boogie666 the RN cljs transformer has been updated to work with the new interfaces in current metro 0.49 : https://gist.github.com/sundbry/55bb902b66a39c0ff83629d9a8015ca4 |
The ignore param doesn't seem to be working. I only need to ignore one file in the app's root dir, yet the transform will still hang when node crashes at 1.43GB of memory usage. If I remove the JSON file, the app builds for release config just fine, so I know even though I'm ignoring the file, babel is still parsing it.
Any ideas? Can't seem to find a solution anywhere. Nothing has had an impact, including attempting to change node's max_old_space_size. |
I have this problem too, how did you solve it? |
Never really did, I ended up having to just download the whole database from within the app on first startup and show a loading screen. Either that or depending on your use case you might be able to make the database smaller by changing long keys to something shorter. That got me under the threshold of size that would actually build, pretty big difference. I changed every key to be one character long. Hopefully this gets fixed some time, wishing you luck. |
Thank you, you are a genius, but it doesn't suit my situation.😟 |
I have solved it. Add following content in ~/.bash_profile
I'm not sure it can suit you, but maybe it could help someone else. |
Do you want to request a feature or report a bug?
Bug.
What is the current behavior?
Metro will either run out of memory or it will give up after 5 minutes of waiting to transform the JS file.
This was first reported here facebook/react-native#8475 and then again here facebook/react-native#12590
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can
yarn install
andyarn test
.I have a repro repo here https://github.com/jeaye/react-native-packager-bug -- it's not in the
yarn
format, since I don't know what that is.What is the expected behavior?
The transformation completes in a timely fashion or metro waits long enough for the transformation to finish in however long it needs. In order to achieve the latter, my production build script currently contains the following:
Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
React Native: 0.50.4
babel-preset-react-native: 4.0.0
Metro (comes with RN): 0.20.3
Node: 9.3.0
OS: Arch Linux x86_64
The text was updated successfully, but these errors were encountered: