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

Compiling is slow #7

Closed
ljl opened this issue Oct 2, 2013 · 20 comments
Closed

Compiling is slow #7

ljl opened this issue Oct 2, 2013 · 20 comments

Comments

@ljl
Copy link

ljl commented Oct 2, 2013

Using grunt-ts, compiling takes almost twice as long as the tsc compiler.

$ time tsc main.ts -out test.js 
real    0m6.366s

$ grunt cm
Running "ts:api" (ts) task
Compiling.
Success: 14.38s for 1 typescript files
@basarat
Copy link
Member

basarat commented Oct 2, 2013

To help debug can you provide the following:

  • Show the ts:api task config in the Gruntfile
  • Time the run for only ts:api so, time grunt ts:api. Run only this line please :)

PS: time for the following config (This should definitely be same as tsc because that is all it does when you got down to it):

ts: {
    dev: {                        // a particular target   
        src: ["main.ts"],
        out: 'test.js'      
    }
}

We are using it on a large project and have friends that use it as well and haven't experienced this so I am really interested in finding the root cause if its grunt-ts. Thanks.

@ljl
Copy link
Author

ljl commented Oct 2, 2013

Thanks for the quick reply.

I checked my Gruntfile and realized it created declaration and sourcemap files.

api: {
    src: ['src/main/webapp/admin2/api/js/main.ts'],
    out: 'src/main/webapp/admin2/api/js/api.js',
    options: {
        sourcemap: true,
        declaration: true
    }
}

So i added this to the tsc compiler, and here are the results:

$ time tsc src/main/webapp/admin2/api/js/main.ts --out test.js --declaration --sourcemap

real    0m6.549s
user    0m6.219s
sys 0m0.373s

$ time grunt ts:api
Running "ts:api" (ts) task
Compiling.
Success: 10.48s for 1 typescript files

Done, without errors.

real    0m11.043s
user    0m15.950s
sys 0m5.109s

Even though i added declaration and sourcemap to tsc, it seems like grunt-ts uses significantly more time.
We have about 5 of these tasks running during a complete build, which adds up to a lot longer compile time.

I also noted that the grunt-ts is very variable, going from between 10 secs and upwards to 15. 11-12 being the most common. tsc however stays about the same, with very little variance (even when adding declaration and sourcemaps).

@ljl
Copy link
Author

ljl commented Oct 2, 2013

I can add that its about 14000 lines of typescript in 302 files.

@basarat
Copy link
Member

basarat commented Oct 2, 2013

Make sure you are using the latest version of grunt-ts. Check your package.json, make sure it reads "grunt-ts": "1.3.0", and then run npm install. If you are on this version and still have the problem please let me know.

TypeScript 0.9.0 had performance issues which were fixed and grunt-ts was upgraded accordingly quite a while back.

PS: we are on around 180 files and it takes about 5s, and so does tsc. If you look at the source code all grunt-ts does is run node tsc : https://github.com/basarat/grunt-ts/blob/master/tasks/ts.ts#L129

@ljl
Copy link
Author

ljl commented Oct 3, 2013

I was actually running 1.1.8, but i switched to 1.3.0 and did npm install. The compile times stayed the same though.

@basarat
Copy link
Member

basarat commented Oct 3, 2013

which version of nodejs are you using?

@ljl
Copy link
Author

ljl commented Oct 3, 2013

v0.9.3

@basarat
Copy link
Member

basarat commented Oct 3, 2013

After further investigation:

$ time tsc @tscommand.tmp.txt

real    0m3.853s
user    0m0.000s
sys     0m0.000s

basaratsyed@PIC-BAS /c/dev/dust/Dust.Web/App-UI (dev)
$ time grunt ts:src
Running "ts:src" (ts) task
Compiling.
Success: 4.92s for 186 typescript files

Done, without errors.

real    0m6.205s
user    0m0.015s
sys     0m0.046s

You can see that grunt-ts takes +1 seconds (for generating reference.ts + loader.js files) and grunt itself takes +1 seconds to warm up and run the task but I don't see why it should take twice the time. I don't have a solution for your case I am afraid

@basarat
Copy link
Member

basarat commented Oct 3, 2013

I am on node v0.10.11 but I don't think that should affect you since your tsc is running on node as well same as grunt-ts. But worth a shot anyways.

@ljl
Copy link
Author

ljl commented Oct 3, 2013

I have been trying to figure this out, so i took a walk around the office to check their compile times.

A coworker with a newer computer compiled the same files in 3.7 sec with tsc and about 4.6 sec with grunt-ts. It seems like the grunt overhead takes exponentially more time with slower hardware.

@tschoartschi
Copy link

@ljl: I have the same issue. Did you find a way to speed things up?

@AlanFoster
Copy link

I am facing similiar issues using

grunt-cli v0.1.13
grunt v0.4.2
node v0.10.24

It seems that a single hello world ts file takes ~4-5 seconds to compile when using the suggested arguments from the readme file - has anyone had any luck with this? :)

@Bartvds
Copy link
Member

Bartvds commented Jan 31, 2014

@basarat I think it could be ShellJS on windows that is slowing things down.

I was browsing their code to see how they can exec() synchronously, then I see this comment:

https://github.com/arturadib/shelljs/blob/master/src/exec.js#L63-L68

  // The wait loop
  // sleepFile is used as a dummy I/O op to mitigate unnecessary CPU usage
  // (tried many I/O sync ops, writeFileSync() seems to be only one that is effective in reducing
  // CPU usage, though apparently not so much on Windows)

The implementation they do to run synchronous is very icky.

Maybe grunt-ts should use asynchronous grunt.util.spawn?

@jeffmay
Copy link

jeffmay commented Jan 31, 2014

I think we would be better off using grunt.util.spawn since it keeps our dependencies slimmer and on a more supported library.

@basarat Any major features that ShellJS gives us that grunt.util.spawn doesn't have?

@basarat
Copy link
Member

basarat commented Jan 31, 2014

The implementation they do to run synchronous is very icky.

Agreed, thanks for pointing it out!

Any major features that ShellJS gives us that grunt.util.spawn doesn't have?

not at all. Just used for convenience.

@basarat
Copy link
Member

basarat commented Feb 24, 2014

@tschoartschi @AlanFoster @ljl due to @Bartvds's excellent work : #64 it should be faster now. Let us know if you experience differences between running tsc manually and grunt-ts.

Use grunt-ts 1.7.1

@basarat basarat closed this as completed Feb 24, 2014
@AlanFoster
Copy link

Great job @Bartvds - I've really noticed a huge speed increase with 1.7.1; The experience is definitely much improved now :)

@Bartvds
Copy link
Member

Bartvds commented Mar 2, 2014

@AlanFoster Thanks, glad it helped. And a tip for power users: because there is no crappy ShellJS anymore to clobber the CPU threads with nonsense you can run builds parallel again (using grunt-concurrent or similar). 🚀

@melroy89
Copy link

I don't have alot of issues, yet I don't like to wait for nothing. Could you please go a bit more into the details on this?

Like are there some best practices / examples (using grunt-ts with grunt parallel or grunt concurrent (or which one is now the best to use?)?

Also does somebody have some special flag and tricks in your tsconfig.json to speed things up?

Thanks!

@nycdotnet
Copy link
Contributor

Best bet for speed of compilation in development with TypeScript is to use built-in watch parameter with tsc or an editor that supports compile on save. Grunt is not optimized for these scenarios because it is based around doing everything from scratch on each build. Grunt is more for consistency than performance.

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

8 participants