plantain-00 / type-coverage

A CLI tool to check type coverage for typescript code
MIT License
1.26k stars 44 forks source link

Maximum call stack size exceeded #89

Closed alexcanessa closed 2 years ago

alexcanessa commented 3 years ago

Hello,

I have a few users getting a RangeError: Maximum call stack size exceeded when running the typescript-coverage-report command, but (as you'll see from https://github.com/alexcanessa/typescript-coverage-report/issues/51#issuecomment-811443024) seems like the bug happens also when running type-coverage directly.

Anyone else?

alexcanessa commented 3 years ago

~@plantain-00 this seems to still be a bug (see the linked issue ^)~

Yonom commented 3 years ago

Also getting this error

macOS Node: v16.3.0 TS: v4.2.2

plantain-00 commented 3 years ago

@Yonom Can you provide a minimal repo to produce this?

Yonom commented 3 years ago

Sure, I'll be busy tomorrow so it might take a day or two before I get around to it

mateodelnorte commented 3 years ago

Also getting this.

Yonom commented 3 years ago

I fixed the problem by deleting node_modules and installing everything again. Sadly I have been unable to reproduce the bug again

robatwilliams commented 3 years ago

I have this when running directly too.

Windows 10 Node v14.15.5 "type-coverage": "2.18.2", - installed locally not globally "typescript": "4.4.3",

The project is huge, and a mix of TS and JS. With allowJs: false it needs --max-old-space-size=8192 and completes successfully, however after turning on JS it needs --max-old-space-size=24576 to avoid running out of heap - but then it exceeds max call stack size.

robatwilliams commented 3 years ago

I found that program.getSourceFiles() is returning files from my dist directory, despite it not being in my tsconfig include. I expect that's a TypeScript issue.

Added --ignore-files 'dist/**' to workaround

robatwilliams commented 3 years ago

When I enable the checker's strict mode, I'm back to max call size exceeded.

Yonom commented 2 years ago

My issue was fixed by deleting node_modules and reinstalling everything. I haven't been able to reproduce it since

albertogasparin commented 2 years ago

I'm also having this issue with a large codebase. I've tried to give 27 of my 32GB of RAM to the process but that is not enough 😞 I wonder if the issue is with sourceFileInfos used to loop over and over across all files (we are talking about 50K+ files) and maintaining a massive map with source information.

Maybe changing the loop to be file by file instead of step by step would help node release the memory of processed files?

plantain-00 commented 2 years ago

I'm also having this issue with a large codebase. I've tried to give 27 of my 32GB of RAM to the process but that is not enough 😞 I wonder if the issue is with sourceFileInfos used to loop over and over across all files (we are talking about 50K+ files) and maintaining a massive map with source information.

Maybe changing the loop to be file by file instead of step by step would help node release the memory of processed files?

sourceFileInfos just contains file path, sourceFile Reference, hash string: https://github.com/plantain-00/type-coverage/blob/58f7d2b94069fa742c59d2d6630e8fb1ab8b7319/packages/core/src/core.ts#L67-L72

It's file by file: https://github.com/plantain-00/type-coverage/blob/58f7d2b94069fa742c59d2d6630e8fb1ab8b7319/packages/core/src/core.ts#L38

My guess about the problem is checking every identifier's type: https://github.com/plantain-00/type-coverage/blob/58f7d2b94069fa742c59d2d6630e8fb1ab8b7319/packages/core/src/checker.ts#L38-L45

albertogasparin commented 2 years ago

Maybe so, but is is a memory issue. It's not a problem of it being slow (yet), it feels like there is a memory leek or something as it keeps growing. So if the issue is there, it means that either getTypeAtLocation or getContextualType leak, otherwise I'd think types would be garbage collected. But I'm still just speculating as didn't have time to put a debugger and look at what is happening

albertogasparin commented 2 years ago

Alright, had time to investigate a bit and found out the the issue is with this fallback as my tsconfig has neither includes nor files. So that generic wildcard '**/*' was matching things like md,json,png, sh, ... and I guess TS would choke trying to read some of them, never finishing the type check and eating all the memory. By setting an explicit includes: ['**/*.{ts,tsx}'] in my tsconfig then TS would handle 50K files just fine, and the program would perform decently.

Wonder if that is what is causing issues to other people here too and if we should make it a bit more specific.

plantain-00 commented 2 years ago

Alright, had time to investigate a bit and found out the the issue is with this fallback as my tsconfig has neither includes nor files. So that generic wildcard '**/*' was matching things like md,json,png, sh, ... and I guess TS would choke trying to read some of them, never finishing the type check and eating all the memory. By setting an explicit includes: ['**/*.{ts,tsx}'] in my tsconfig then TS would handle 50K files just fine, and the program would perform decently.

Wonder if that is what is causing issues to other people here too and if we should make it a bit more specific.

According to typescript document (https://www.typescriptlang.org/tsconfig#include ), if files is not specified, the default value of include is ** 屏幕快照 2022-04-27 11 24 15 And typescript will support .mts and cts, so **/*.{ts,tsx} will break.