1

I switched my codebase to typescript. It's around 100k lines of codes in hundreds of files.

Before my launch time was 2 seconds with ESLint --fix --cache. Now with Typescript (ts-node) it is 25 seconds (20 seconds is typescript only).

The project is backend only.

25 seconds is kind of unacceptable speed. Is this normal? I tried to remove every dynamic require I could find but still didn't help. Could it be some large file that is taking too long? How can I know what's taking so long?

2 Answers 2

1

You do not have to run production build with ts-node, it just transpiles your code on a fly. You can simply check it, run ts-node and paste some code, then try to see sources of runtime code. Also compilation level and other configurations matter at your tsconfig file.

> const a = (a: string) => a + 'hello';
undefined
> a.toString()
"function (a) { return a + 'hello'; }"

So when you run your project it:

  • Typechecks your every file
  • Transpiles your every file
  • Interprets such file
  • Then only runs your code

As it is an interpreted process so your time goes to (require -> typecheck -> transpile -> run -> repeat) till all your code is executed. As your codebase is cascade you my run into performance issues on typechecking

Sign up to request clarification or add additional context in comments.

5 Comments

so how do I improve or debug compiling speed? My goal is to reduce the 25 seconds launch time.
This time is ok for 100k lines of codes in hundreds of files If you want to run production build simple create dist from your project by setting include, exclude, outDir you tsconfig.json file and simply run it like any other js project
Also you can use incremental flag to improve compilation performance Or --transpile-only flag to ts-node to transpile without type checking
Look also at github.com/TypeStrong/ts-node/issues/754 conversation, it might help
Did you manage to resolve this? In our project it takes 25 seconds as well. I've tried the transpileOnly & incremental flags, but it doesn't help much.
0

Two solutions for dev env only

  • Use tsc --watch, it will rebuild on file changes and is very fast since it rebuild only the changed files

OR

  • Use ts-node-dev. It's a mix of ts-node and nodemon or pm2. So it recompiles and restart server on file changes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.