Skip to content
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

Memory leak with vue-tsc #2210

Closed
scottbedard opened this issue Dec 14, 2022 · 4 comments
Closed

Memory leak with vue-tsc #2210

scottbedard opened this issue Dec 14, 2022 · 4 comments

Comments

@scottbedard
Copy link

scottbedard commented Dec 14, 2022

Hi, I'm running into a memory problem while attempting to use vue-tsc on a very large codebase. A similar issue was discussed here, #1106. I've been trying to reproduce the issue in a separate repo, but so have not been able to.

Here is my current setup

  • node - 16.13.0
  • typescript - 4.5.4
  • vue-tsc - 1.0.13
  • vue - 2.7.10

I've tried updating node and typescript to latest versions, but that still produced the same error. For now, we've been able to side-step the issue by setting node options --max-old-space-size=7168, but this problem is still causing friction elsewhere with the team and in our CI pipeline. Any help would be greatly appreciated.

./node_modules/.bin/vue-tsc --noEmit --pretty --allowJs

<--- Last few GCs --->

[63185:0x130008000]    40566 ms: Scavenge 4035.0 (4124.2) -> 4030.2 (4126.9) MB, 7.9 / 0.0 ms  (average mu = 0.801, current mu = 0.750) allocation failure
[63185:0x130008000]    40607 ms: Scavenge 4037.8 (4126.9) -> 4036.5 (4133.7) MB, 18.2 / 0.0 ms  (average mu = 0.801, current mu = 0.750) allocation failure
[63185:0x130008000]    42252 ms: Mark-sweep 4045.0 (4133.7) -> 4039.2 (4145.2) MB, 1624.6 / 0.0 ms  (average mu = 0.651, current mu = 0.110) allocation failure scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0x104c6e36c node::Abort() [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
 2: 0x104c6e4f4 node::errors::TryCatchScope::~TryCatchScope() [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
 3: 0x104dbb378 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
 4: 0x104dbb30c v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
 5: 0x104f3eafc v8::internal::Heap::GarbageCollectionReasonToString(v8::internal::GarbageCollectionReason) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
 6: 0x104f3d61c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
 7: 0x104f488f8 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
 8: 0x104f4898c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
 9: 0x104f1b844 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
10: 0x105250b20 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
11: 0x10556508c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
12: 0x1054fbcac Builtins_GrowFastSmiOrObjectElements [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
13: 0x10a2668c4
14: 0x10a46d024
15: 0x10a65d490
16: 0x10a49a064
17: 0x10a0fabb0
18: 0x10a24dfb4
19: 0x109ae5aa0
20: 0x10a493cf0
21: 0x109ae613c
22: 0x10a0f8140
23: 0x10a66ddf4
24: 0x10a49a2cc
25: 0x10a0fabb0
26: 0x10a24dfb4
27: 0x109ae5aa0
28: 0x10a493cf0
29: 0x109ae613c
30: 0x10a36b0f0
31: 0x10a265c54
32: 0x10a3d1ebc
33: 0x10a49a274
34: 0x10a0fabb0
35: 0x10a24dfb4
36: 0x109ae5aa0
37: 0x10a493cf0
38: 0x109ae613c
39: 0x10a0f8140
40: 0x10a66ddf4
41: 0x10a49a2cc
42: 0x10a0fabb0
43: 0x10a24dfb4
44: 0x109ae5aa0
45: 0x10a493cf0
46: 0x109ae613c
47: 0x109d9755c
48: 0x10a5d725c
49: 0x10a265c54
50: 0x10a308798
51: 0x10a675528
52: 0x10a453144
53: 0x10a0d8500
54: 0x10a65d5dc
55: 0x10a49a064
56: 0x10a0fabb0
57: 0x10a24dfb4
58: 0x109ae5aa0
59: 0x10a493cf0
60: 0x109ae613c
61: 0x10a0f8140
62: 0x10a66ddf4
63: 0x10a49a2cc
64: 0x10a0fabb0
65: 0x10a24dfb4
66: 0x109ae5aa0
67: 0x10a493cf0
68: 0x109ae613c
69: 0x10a0f8140
70: 0x10a674b60
71: 0x109bd8180
72: 0x10a34cbe4
73: 0x109aa9adc
74: 0x10a428350
75: 0x10a355180
76: 0x10a26f54c
77: 0x10a6e6060
78: 0x10a352cd8
79: 0x10969b618
80: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
81: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
82: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
83: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
84: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
85: 0x1055af308 Builtins_ProxyGetProperty [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
86: 0x1055eadbc Builtins_LdaNamedPropertyHandler [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
87: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
88: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
89: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
90: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
91: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
92: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
93: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
94: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
95: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
96: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
97: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
98: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
99: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
100: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
101: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
102: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
103: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
104: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
105: 0x1054f8d18 Builtins_InterpreterEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
106: 0x1054f6b0c Builtins_JSEntryTrampoline [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
107: 0x1054f67a4 Builtins_JSEntry [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
108: 0x104ecb220 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
109: 0x104eca8b4 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
110: 0x104dd7e70 v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
111: 0x104c3d3fc node::ExecuteBootstrapper(node::Environment*, char const*, std::__1::vector<v8::Local<v8::String>, std::__1::allocator<v8::Local<v8::String> > >*, std::__1::vector<v8::Local<v8::Value>, std::__1::allocator<v8::Local<v8::Value> > >*) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
112: 0x104c3e3d8 node::StartExecution(node::Environment*, char const*) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
113: 0x104c3e284 node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
114: 0x104bc1b50 node::LoadEnvironment(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
115: 0x104ca76c4 node::NodeMainInstance::Run(int*, node::Environment*) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
116: 0x104ca73c0 node::NodeMainInstance::Run(node::EnvSerializeInfo const*) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
117: 0x104c402dc node::Start(int, char**) [/Users/scottbedard/.nvm/versions/node/v16.13.0/bin/node]
118: 0x10939d08c
zsh: abort      ./node_modules/.bin/vue-tsc --noEmit --pretty --allowJs
@johnsoncodehk
Copy link
Member

johnsoncodehk commented Dec 14, 2022

  1. Have you tried using https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.vscode-tsconfig-helper to debug if tsconfig contains unneeded files?
  2. You can also tsc --extendedDiagnostics, --generateTrace debug flags (I know it from --extendedDiagnostics and --generateTrace do not work #1375)
  3. Can memory usage be significantly reduced if you set vueCompilerOptions.skipTemplateCodegen = true in tsconfig?
  4. Run Volar (Debug): Server Stats command in VSCode, and check "largest 10 files:" from VSCode output panel to see if there has any ridiculously big files.
  5. Recursive type calculation may also cause this problem. If this is the reason, it cannot be easily checked. You need to dichotomize the files included in the project to see if there is a significant impact.

@scottbedard
Copy link
Author

Hi, thanks for the fast response!

  1. I've tried this, and it doesn't appear anything extra is included. Node modules, dist files, and so on are all excluded
  2. These commands may be helpful, but I'm not an expert on how to read these files. I'm beginning to educate myself using the TS wiki about it. The output for the expanded diagnostics is listed below
  3. Changing this wasn't meaningfully different, and it negated a lot of the type-checking we want inside our templates
  4. I didn't receive any output running this command, it may have been failing. I asked a co-worker to run it and they had the same result of no output
  5. I'm not sure what you're describing here. Are you suggesting running the type checker more granularly on the codebase until the memory leak is found?
NODE_OPTIONS='--max-old-space-size=7168' ./node_modules/.bin/vue-tsc --noEmit --allowJs --extendedDiagnostics --generateTrace trace
Files:                        12371
Lines of Library:             27100
Lines of Definitions:        237891
Lines of TypeScript:         378490
Lines of JavaScript:        1824886
Lines of JSON:                   98
Lines of Other:                   0
Nodes of Library:            117083
Nodes of Definitions:        517567
Nodes of TypeScript:        2297800
Nodes of JavaScript:        9998074
Nodes of JSON:                  189
Nodes of Other:                   0
Identifiers:                3034662
Symbols:                    3574679
Types:                       790372
Instantiations:             6027492
Memory used:               7256758K
Assignability cache size:    556041
Identity cache size:          69189
Subtype cache size:           70261
Strict subtype cache size:    44710
I/O Read time:                1.15s
Parse time:                   8.17s
Total time:                   0.00s

@johnsoncodehk
Copy link
Member

johnsoncodehk commented Dec 22, 2022

The most likely reason is that there are too many code (especially .js), so the memory usage increases proportionally. Are you sure 12371 files is a normal number for your project?

If yes, you might consider splitting the project and including them by multiple tsconfigs, changing the execution of a one time tsc to multiple times tsc execute against multiple smaller tsconfigs: https://github.com/microsoft/TypeScript/wiki/Performance#performance-considerations

And you can try to refer to #2214 author's method to disable allowJs.

  1. I didn't receive any output running this command, it may have been failing. I asked a co-worker to run it and they had the same result of no output

See #2214 (comment)

@johnsoncodehk
Copy link
Member

Closed, as this is not a problem that Volar seems to be able to solve.

Also, to check that the project correctly contains the necessary files, you can use https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.vscode-tsconfig-helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants