amplify-codegen icon indicating copy to clipboard operation
amplify-codegen copied to clipboard

`npm i` followed by `idealBuild:amplify-codegen-appsync-model-plugin`, and `amplify codegen` commands run out of memory when Query Depth is >= 5

Open mlabieniec opened this issue 3 years ago • 1 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v16.19.0 npm -v 8.19.3

Amplify CLI Version

N/A

What operating system are you using?

Ubuntu 22.04.1 LTS

Amplify Codegen Command

Not applicable

Describe the bug

When running npm i on a large project idealTree:amplify-codegen-appsync-model-plugin hangs for several minutes, causes fans to spin up heavily, uses 1.8GB of memory and eventually fails due to out of memory exception. In addition, once it starts ctrl+c doesn't kill the process, terminals to be closed and process manually killed. Finally, the resulting JavaScript file also is massive e.g. 20+ Megabytes. If left for about 15-20 minutes, ultimately build fails with FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

image

image

This seems to not occur when using yarn instead of npm, however running an amplify codegen locally to generate the javascript file (with a query depth of 6), also causes the out of memory exception. The only solution is to increase the javascript heap size:

export NODE_OPTIONS=--max_old_space_size=4096

Without doing this the process also crashes, so there is definitely a memory leak in the codegen, I actually had to increase this to 6GB to even get it to complete.

Expected behavior

npm i works on my project and amplify-codegen-appsync-model-plugin works/completes amplify codegen works with less than 4GB dedicated memory to node process

Reproduction steps

  1. run npm i on a project with a large schema and larger query depth
  2. watch it hang on idealTree:amplify-codegen-appsync-model-plugin (ctrl+c no longer breaks either)
  3. try and force quit npm i process

GraphQL schema(s)

Can share privately if needed.

Log output

$ amplify codegen
✔ Generated GraphQL operations successfully and saved at src/graphql
⠋ Generating

<--- Last few GCs --->

[64889:0x4486d70]    34353 ms: Mark-sweep (reduce) 2041.6 (2052.1) -> 2041.4 (2053.6) MB, 726.2 / 0.0 ms  (average mu = 0.187, current mu = 0.111) allocation failure GC in old space requested
[64889:0x4486d70]    35084 ms: Mark-sweep (reduce) 2041.9 (2052.6) -> 2041.8 (2053.9) MB, 730.4 / 0.0 ms  (average mu = 0.093, current mu = 0.002) allocation failure GC in old space requested

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x8de370 node::Abort() [/home/michael/.amplify/bin/amplify]
 2: 0x82772b node::FatalError(char const*, char const*) [/home/michael/.amplify/bin/amplify]
 3: 0x9f2a76 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/home/michael/.amplify/bin/amplify]
 4: 0x9f2d0d v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/home/michael/.amplify/bin/amplify]
 5: 0xb95135  [/home/michael/.amplify/bin/amplify]
 6: 0xb95b87 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/home/michael/.amplify/bin/amplify]
 7: 0xb9e708 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/home/michael/.amplify/bin/amplify]
 8: 0xba1d30 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/home/michael/.amplify/bin/amplify]
 9: 0xb6b352 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/home/michael/.amplify/bin/amplify]
10: 0xe716af v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [/home/michael/.amplify/bin/amplify]
11: 0x1769439  [/home/michael/.amplify/bin/amplify]


Additional information

amplify-codegen-appsync-model-plugin has a memory leak when larger (5-6) query depth chosen resulting in a huge javascript file (20+MB).

mlabieniec avatar Dec 17 '22 14:12 mlabieniec

Hi @mlabieniec - thank you for reporting, could you run amplify diagnose and share the diagnostic id w/ the team as well to help us reproduce your use-case here?

alharris-at avatar Mar 21 '23 17:03 alharris-at