-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
Compilation is unbelievably slow #754
Comments
I have also experienced this issue when running alsatian tests after upgrading to ts-node v7. I've found I can resolve the issue by specifying the The problem seems to stem from the fact that the test framework @blakeembrey does this sound like a plausible diagnosis, and can you see any better solution? |
Have you tried |
I've run into similar issue today. After ts-node upgrade from 7.0.1 to 8.0.1 my mocha test suite became very slow (32s vs 4s). Adding TS_NODE_TRANSPILE_ONLY=true resolved my issue. Thanks @cspotcode |
|
I tried all the proposed solutions. The |
That's intereseting, Ideally |
I've hit this issue too after updating from 7.0.1 to 8.0.1. From what I can tell when Line 484 in 544851e
This seems to create an invalid config (when using TypeScript 3.2.4):
Removing the |
If anyone can give me temporary access to a slow repo, let me know! I can quickly take a look into the issue and happy to sign any NDA, etc you need. If not, can I get a sense of peoples Let's try with reactions:
|
8.0.2 hasn't made any difference for me. The fact it's adding I can't share our project unfortunately - but here's our
|
@garethflowers Are you using Alternatively, can you try populating |
@blakeembrey I've made a minimal repro at https://github.com/davidgruar/tsnode-perf-repro - please check it out and have a play. Loading just three test files with fairly few dependencies takes more than a second, and the more imports you add, the longer it takes. |
It doesn't seem like a huge overhead when you time the entire program, instead of just requires: There is a difference, however, so for testing it might make the most sense to enable |
Ok, perfect. It does look like TypeScript makes 4x the number of requests to the filesystem when |
i've found several settings contributing to slow compile times, im pretty sure the issue is related to settings that will delete the default setting of ignore: node_modules. IE: allowJs. Others that may also (just from my memory of guess/check) are removeComments, emitDecoratorMetadata, and a few others. I've also noticed that if you glob without file ext like include: src//* instead of src//*.ts it can cause slowdowns , idk if its chokadir watching fontfiles that may be in there or something. using isolatedModules is the sure-fire way to speed things up though. |
@jeremy-coleman Sorry, I couldn't quite follow. Can you please let me know who you/what are responding to here? Edit: I don't think any of those are related to the root cause of issues mentioned in this thread, that's all. |
@blakeembrey Hi, I also created an example: https://github.com/lukashavrlant/ts-node-perf But I guess it is similar to the previous example. Basically compiling TS files to JS files and then running mocha tests using the generated JS files is faster then using ts-node directly. See readme for more details please. The more imports I use is test files, the slower it gets. For the sake of example I used zero imports in tests files. |
Unfortunately this definitely seems to be the case. I'm not 100% sure why in the language services this is so expensive. It appears that changing |
@sheetalkamat would you know what would need to be done to allow API implementers to persist the resolution cache across builds? |
When host doesn't have resolveModuleName it creates the cache per program. So whenever program changes the new resolution cache is created. (Note this is different from internal resolution cache that tsc and tsserver use that are made aware of which files have changed and hence which resolutions to invalidate) I don't think |
I'm also having issues with speed. I'm having a big Angular Application where I am running protractor tests with the jasmine framework. When I start the tests with protractor flag --troubleshoot i can see where it gets to the point where the files get processed. Usually that takes like +- 3 seconds and after that jasmine starts. Having version 8.0.0 and above its taking up to almost 2 Minutes until the files are processed and jasmine starts. Sadly I don't know where I could try out the solution with file: false. Any help is appreciated. |
It's not a solution, but downgrade to 6.2.0 helped me currently with the test performace issues. |
For now, please try using the environment flag from https://github.com/TypeStrong/ts-node#cli-and-programmatic-options - |
ts-node 7.0 -- 2.5s same environment. |
@miao17game By same environment, is this a test suite, a script or something else? |
Hi -- for what it's worth -- We have a rather large code base (no way to know really...) It is on the order of 450 Mocha tests. 7.x was not "snappy" to startup - but it was tolerable. I upgraded from 7.0.2 to 8.0.1 and the tests will actually never finish on Windows. They work fine on Linux (like 7.x). After reading through this, I was trying to use the On the code base with 450 tests... it simply never finished. The strange thing is if I set the environment variable TS_NODE_FILES -- If it helps:
tsconfig.json {
"compilerOptions": {
"target": "es6",
"outDir": "dist",
"rootDir": "src",
"moduleResolution": "node",
"module": "commonjs",
"declaration": true,
"importHelpers": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"listFiles": false,
"traceResolution": false,
"pretty": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny" : true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"es6",
"dom",
"dom.iterable"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules/**"
],
"compileOnSave": false
} package.json "ts-node": "^8.0.2",
"typescript": "3.3.3"
"tslib": "^1.9.3", |
We have just started running into this problem after upgrading our Angular app to 7.2.5 and at the same time we also upgraded ts-node to 8.0.2. Since the upgrade running the protractor e2e tests always took about 2 minutes before they would start running. After some investigation I found that it was taking a long time loading the spec files. I've had to downgrade ts-node back to 5.0.1 which fixes it but just wondering if anyone else has had the same problem and if they were able to solve it with the latest ts-node version. |
I'm facing this issue when writing tests using mocha + proxyquire. transpileOnly: true,
typeCheck: false,
files: false |
@acro5piano could you explain how you do that please 🙏 |
@Alexandredc instead of having your nodemon config watch your |
My current solution is tsc + nodemon, but I'm still doing the configuration for Ava. The basics are: # Directory structure
repo/
|- tsconfig.json
|- package.json
|- src/
| `- index.ts
`- build/
`- index.js // tsconfig.json
{
"compilerOptions": {
"outDir": "./build", // <-- important
"noEmit": false, // <-- important
"target": "es2019",
"sourceMap": true,
"incremental": true,
"isolatedModules": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true
}
} // package.json
"scripts": {
"dev": "concurrently yarn:dev:*",
"dev:nodemon": "nodemon build/index.js",
"dev:tsc": "tsc -w"
}, And the last thing is to add deps:!
edited: You may also needs |
I've met same issue on developing web app/API server using express + ts-node-dev(ts-node). express-lazy-router help us to reduce the compilation time at start time by compiled when needed. |
Can you use the power of esbuild? https://esbuild.github.io/ |
@kfrajtak Edit: I'm using Edit 2: I've tried to use other project using decorator, but its Interpolation is still different from original |
See also: #1160 which allows opting into the swc compiler via ts-node. |
Could |
I investigated esbuild when implementing #1160 but there were performance limitations in per-file compilation. #1160 gives the same performance benefits, and people are already successfully using it, for example #1276 (reply in thread) I recommend checking it out and giving feedback in the discussion thread. #1160 implements pluggable transformers. The swc transformer is built-in, but anyone can write a plugin to use any other transformer. This means your existing TS project configuration is all you need to use a different transformer, and you get the same benefits as ts-node: sourcemap support, ESM loader, etc. Also, for many people, |
The new features mentioned above, https://github.com/TypeStrong/ts-node/releases/tag/v10.0.0 There is a dedicated discussion thread linked if you need assistance with the upgrade. |
Closing because some solutions are already available (
|
In my case with |
@O-Q thank you, man. That helps me to start test faster! |
Could this be a solution? |
@thousandsofraccoons ts-node's "swc" integration is the recommended solution here. It skips typechecking and uses the blazing-fast swc transpiler. You can use it today, check the docs links below for instructions. https://typestrong.org/ts-node/docs/performance#skip-typechecking It is promoted out of "experimental" status in our next, upcoming release. #1536 |
FYI Running with |
We've seen a lot of cases where someone thought they were using transpileOnly, but actually they weren't. So that's always a possibility whenever it doesn't seem like transpileOnly is making much impact: perhaps it's not even turned on. Is this an issue with cross-file metadata, in other words, is it compatible or incompatible with |
Yeah, I believe only tsc (and ts-node without SWC) can handle Thus, I stopped using decorators. Moved from mikro-orm to objection, Type-GraphQL to Nexus, remove tsyringe, then moved from ts-node to esbuild. Now things became much better. |
@cspotcode I tried all the options -- cli argument, environment variable and
I... have no idea. Looks like @acro5piano knows more about this 😄 |
Compilers such as babel, swc, and esbuild do not understand type information. If type information from one file affects the emitted code from another file, it will fail to emit the code you're expecting using these tools. TypeScript has an option https://www.typescriptlang.org/tsconfig/#isolatedModules This is an important detail to understand: these errors are raised when using TypeScript to typecheck, not when using babel, swc, or esbuild to compile your code! The assumption here is that you run typechecking as part of your automated testing even when you use a non-typechecking compiler. Think of the typechecker as a lint step. Unfortunately, the reason I closed this issue still applies here: |
Another thing worth mentioning: |
Of course! I'm planning on creating such a fake repo. I just need time :) |
Awesome, thank you! Feel free to share it here or create a separate issue if that would help to focus the conversation. |
The strangest thing happened. I undid all the configuration changes I made yesterday, Sorry for all the fuss. |
Hi, for some reason we have performance problems when using ts-node in our mocha tests. It takes about 500 ms to compile an empty ts file. I added some console.logs to measure the time to run this very line:
const output = service.getEmitOutput(fileName)
and this line takes 500 ms to run even though the content of the file is an empty string (thecode
variable on the line 314 is empty string). Actually, all our tests files take too long to process, while the production files take a few milliseconds to compile. So any*.spec.ts
takes about 500 ms to compile, a regular*.ts
file takes about 20 ms. Do you have any idea what could be the root cause or how should I debug it more?We use latest mocha, ts-node and typescript, but we tried some old versions too and the problem persists. The
tsconfig.json
:The text was updated successfully, but these errors were encountered: