Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript compiler becomes slow?

Tags:

typescript

I'm developing Win8 app with TypeScript.

To compile my typescript code, I added winrt.d.ts and winjs.d.ts then referenced them using:

<reference path="winrt.d.ts" static="true" />
<reference path="winjs.d.ts" static="true" />

Compile & build succeeded but IDE's intelliSense was being very slow. I simply opened winrt.d.ts and checked the file. The file has 18,770 lines which is really huge file to compile on the fly.

Are there any options or methods to reference those huge definition file without compile again just like lib.d.ts?

This slowness seriously hurts my TypeScript selection.

UPDATED:

On the current compiler version (0.8.0), there is no solution. Hope to see best performance gain in near future release.

UPDATED:

Here is my simply hack to boost dev. performance. I simply created winrt.compact.d.ts. Then copy only part of namespaces which are actually used and save the file.

Fortunately the file(winrt.d.ts) looks like being generated from several declaration files. So each namespace is clearly separated from others. It is much easier to make compact version for WinRT.

like image 805
popopome Avatar asked Oct 16 '12 01:10

popopome


People also ask

Is TypeScript compiler slow?

TypeScript is slow by nature. Its performance degrades with the file size, and the relation is likely non-linear.

How do I speed up TypeScript compilation?

The first thing that we can consider doing to improve performance, is to skip type checking between other files by setting the isolatedModules compiler option to true . This brings the average compile time down to 9.09 seconds , a 32% reduction in time (not bad for a quick setting change).

Does TypeScript affect performance?

Things to Remember. Code generation is independent of the type system. This means that TypeScript types cannot affect the runtime behavior or performance of your code. It is possible for a program with type errors to produce code (“compile”).

Is TypeScript a waste of time?

TypeScript is great but sometimes, using it can turn out to be an unnecessary waste of time. Being a former C# programmer, I'm a big fan of TypeScript and strongly-typed programming languages — having said that, I know better than to use it in every project.


Video Answer


2 Answers

Correct me if I'm wrong, but I don't think that lib.d.ts is being treated in any special way by the compiler. I took a look at the source code and here is the snippet that deals with lib.d.ts:

if(this.compilationSettings.useDefaultLib) {
    var compilerFilePath = this.ioHost.getExecutingFilePath();
    var binDirPath = this.ioHost.dirName(compilerFilePath);
    var libStrPath = this.ioHost.resolvePath(binDirPath + "\\lib.d.ts");
    code = new TypeScript.SourceUnit(libStrPath, null);
    this.compilationEnvironment.code.push(code);
}     

If the user requests lib.d.ts to be included, it is simply added to the compilation environment as the first piece of code to compile. All other source files (stored in opts.unnamed are added in exactly the same way:

for(var i = 0; i < opts.unnamed.length; i++) {
    code = new TypeScript.SourceUnit(opts.unnamed[i], null);
    this.compilationEnvironment.code.push(code);
}  

So if lib.d.ts is not being treated in a special way then this is also not possible for other (declaration) files. Also, on my system lib.d.ts has 7,677 lines, which is way less than the reported 18,770 for winrt.d.ts, so it may be that the sum of all the lines is just too much for the compiler to achieve acceptable speed.

Other than that, my only idea is that "something else" is causing the slowdown of your machine. If you provide me with a link to the libraries and a snippet of your code, I can at least measure how long a compilation run takes on my system.

like image 109
Valentin Avatar answered Oct 06 '22 18:10

Valentin


There is currently a work item outstanding for this issue on Codeplex:

http://typescript.codeplex.com/workitem/265

There is nothing you can currently do to improve this (except give the compiler more hardware!) But hopefully the work item will be picked up and the issue will be resolved.

like image 32
Fenton Avatar answered Oct 06 '22 19:10

Fenton