Skip to content

Compiler 1.8.2 hangs when building an array of two classes #7293

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

Closed
Tragetaschen opened this issue Feb 29, 2016 · 22 comments
Closed

Compiler 1.8.2 hangs when building an array of two classes #7293

Tragetaschen opened this issue Feb 29, 2016 · 22 comments
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@Tragetaschen
Copy link

TypeScript Version:

1.8.2

Code

import {BehaviorSubject} from 'rxjs/Rx';

class Foo extends BehaviorSubject<string> {
}

class Bar extends BehaviorSubject<any>{
}

var ARRAY = [
    Foo,
    Bar,
];

The BehaviorSubject is a requirement, just using a local, generic class makes it work. I haven't tried further reducing the base class. Once you comment out one of the two array members, the compiler doesn't hang anymore.

Here is my package.json snippet:

  "devDependencies": {
    "typescript": "1.8.2"
  },
  "dependencies": {
    "rxjs": "5.0.0-beta.2"
  }
@mhegazy mhegazy added the Bug A bug in TypeScript label Feb 29, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone Feb 29, 2016
@Tragetaschen
Copy link
Author

Hmm, isn't this regression introduced with 1.8 not going to be fixed in the 1.8 service release?

@mhegazy
Copy link
Contributor

mhegazy commented Feb 29, 2016

We do not know much details about the issue yet, so i can not speculate about which release it will go in.

@vladima
Copy link
Contributor

vladima commented Feb 29, 2016

  1. I don't see the hang
  2. this is not a regression but rather a consequence of the fact that lots of type/method signatures in rxjs-5.0.0-beta.2 become much more complicated - compilation time when using rxjs-5.0.0-beta.1 is significantly smaller than with beta.2. We already have a few issues that track this behavior.
vladima@vladima-ux31a:~/sources/playground/7293$ cat main.ts 
import {BehaviorSubject} from 'rxjs/Rx';

class Foo extends BehaviorSubject<string> {
}

class Bar extends BehaviorSubject<any>{
}

var ARRAY = [
    Foo,
    Bar,
];
vladima@vladima-ux31a:~/sources/playground/7293$ cat package.json 
{
  "name": "7293",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "typescript": "^1.8.2"
  },
  "dependencies": {
    "rxjs": "^5.0.0-beta.2"
  }
}
vladima@vladima-ux31a:~/sources/playground/7293$ ./node_modules/.bin/tsc --m commonjs main.ts -t es6 --diagnostics 
Files:              60
Lines:           20044
Nodes:           95727
Identifiers:     37260
Symbols:       2089459
Types:          355676
Memory used:   491192K
I/O read:        0.01s
I/O write:       0.02s
Parse time:      0.38s
Bind time:       0.24s
Check time:     13.62s
Emit time:       0.07s
Total time:     14.30s
vladima@vladima-ux31a:~/sources/playground/7293$ npm install [email protected] --save
[email protected] /home/vladima/sources/playground/7293
└── [email protected] 

npm WARN EPACKAGEJSON [email protected] No description
npm WARN EPACKAGEJSON [email protected] No repository field.
vladima@vladima-ux31a:~/sources/playground/7293$ ./node_modules/.bin/tsc --m commonjs main.ts -t es6 --diagnostics 
Files:              47
Lines:           19593
Nodes:           89690
Identifiers:     34633
Symbols:       1193175
Types:           39842
Memory used:   104180K
I/O read:        0.01s
I/O write:       0.00s
Parse time:      0.34s
Bind time:       0.22s
Check time:      1.89s
Emit time:       0.03s
Total time:      2.48s

@Tragetaschen
Copy link
Author

Ouch:
I try what you did on a Linux machine and it works (~9 seconds).

~/sources/typescript-hang $ node --version
v0.10.36
~/sources/typescript-hang $ npm install
npm WARN package.json [email protected] No description
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm http GET https://registry.npmjs.org/rxjs/5.0.0-beta.2
npm http GET https://registry.npmjs.org/typescript/1.8.2
npm http 200 https://registry.npmjs.org/rxjs/5.0.0-beta.2
npm http 200 https://registry.npmjs.org/typescript/1.8.2
npm http GET https://registry.npmjs.org/rxjs/-/rxjs-5.0.0-beta.2.tgz
npm http GET https://registry.npmjs.org/typescript/-/typescript-1.8.2.tgz
npm http 200 https://registry.npmjs.org/rxjs/-/rxjs-5.0.0-beta.2.tgz
npm http 200 https://registry.npmjs.org/typescript/-/typescript-1.8.2.tgz
npm WARN engine [email protected]: wanted: {"npm":">=2.0.0"} (current: {"node":"v0.10.36","npm":"1.3.6"})
[email protected] node_modules/rxjs

[email protected] node_modules/typescript
~/sources/typescript-hang $ ./node_modules/.bin/tsc --m commonjs main.ts -t es6 --diagnostics
Files:              60
Lines:           20044
Nodes:           95727
Identifiers:     37260
Symbols:       2089459
Types:          355676
Memory used:   474883K
I/O read:        0.01s
I/O write:       0.01s
Parse time:      0.19s
Bind time:       0.18s
Check time:      8.48s
Emit time:       0.04s
Total time:      8.89s

I try it on my Windows machine (in a PowerShell), and it hangs (running for 5 minutes now, on a SP4).

PS C:\Users\kairu\Source\Repos\Typescript-hang> node --version
v0.12.2
PS C:\Users\kairu\Source\Repos\Typescript-hang> npm install
npm WARN package.json [email protected] No description
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
[email protected] node_modules\rxjs

[email protected] node_modules\typescript
PS C:\Users\kairu\Source\Repos\Typescript-hang> .\node_modules\.bin\tsc --m commonjs main.ts -t es6 --diagnostics

@vladima
Copy link
Contributor

vladima commented Mar 1, 2016

Can you try to upgrade node on Windows machine to 5 and re-run the test?

@Tragetaschen
Copy link
Author

That works. v0.12.2 is what's shipping with VS, though.

PS C:\Users\kairu\Source\Repos\Typescript-hang> node --version
v5.7.0
PS C:\Users\kairu\Source\Repos\Typescript-hang> .\node_modules\.bin\tsc --m commonjs main.ts -t es6 --diagnostics
Files:              60
Lines:           20044
Nodes:           95727
Identifiers:     37260
Symbols:       2089459
Types:          355676
Memory used:   495664K
I/O read:        0.02s
I/O write:       0.02s
Parse time:      0.26s
Bind time:       0.15s
Check time:      6.72s
Emit time:       0.09s
Total time:      7.22s

@vladima
Copy link
Contributor

vladima commented Mar 1, 2016

this is unfortunate. There were some changes in node 0.12 that significantly regressed performance of TypeScript compiler so this is a known issue.

@Tragetaschen
Copy link
Author

When running against my actual project, the process runs out of memory, though:

PS C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument> .\node_modules\.bin\tsc --version
Version 1.8.2
PS C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument> .\node_modules\.bin\tsc -p App --diagnostics

<--- Last few GCs --->

   67568 ms: Scavenge 1418.3 (1514.3) -> 1418.3 (1514.3) MB, 48.5 / 0 ms (+ 0.0 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
   69086 ms: Mark-sweep 1418.3 (1514.3) -> 1413.0 (1514.3) MB, 1510.9 / 0 ms (+ 0.0 ms in 2 steps since start of marking, biggest step 0.0 ms) [last resort gc].
   70571 ms: Mark-sweep 1413.0 (1514.3) -> 1414.0 (1514.3) MB, 1484.5 / 0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0000035D73DE3AD1 <JS Object>
    1: propertiesRelatedTo(aka propertiesRelatedTo) [C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument\node_modules\typescript\lib\tsc.js:16210] [pc=000001D2054FAE48] (this=0000035D73D04189 <undefined>,source=0000003E3E0E93C9 <a Type with map 00000364947F3451>
,target=0000025E4C0C6569 <a Type with map 00000364947F3451>,reportErrors=0000035D73D04299 <false>)
    2: objectTypeRelatedT...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

Here is the same using 1.7.5:

PS C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument> .\node_modules\.bin\tsc -p App --diagnostics
Files:             466
Lines:           49550
Nodes:          183729
Identifiers:     60901
Symbols:        123768
Types:           51349
Memory used:   166080K
I/O read:        0.04s
I/O write:       0.15s
Parse time:      1.33s
Bind time:       0.37s
Check time:      2.02s
Emit time:       0.50s
Total time:      4.23s

@vladima
Copy link
Contributor

vladima commented Mar 1, 2016

good point, let me check we've regressed

@Tragetaschen
Copy link
Author

I as able to avoid the problem in my code base:

The array of types from the repro was reduced from my angular2 application and contains providers for several services. When I cast all the elements of the array to <any>, then I can successfully use 1.8.2 to compile my project.

So with the equivalent of

var ARRAY = [
    <any>Foo,
    <any>Bar,
];

I get this:

PS C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument> .\node_modules\.bin\tsc --version
Version 1.8.2
PS C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument> .\node_modules\.bin\tsc -p App --diagnostics
Files:             466
Lines:           49654
Nodes:          192369
Identifiers:     68963
Symbols:      17569807
Types:           47212
Memory used:   163919K
I/O read:        0.10s
I/O write:       0.17s
Parse time:      0.78s
Bind time:       0.34s
Check time:      1.99s
Emit time:       0.50s
Total time:      3.61s

@vladima
Copy link
Contributor

vladima commented Mar 1, 2016

I've found the offending commit and now checking if we can partially revert its changes.

@vladima
Copy link
Contributor

vladima commented Mar 2, 2016

Fix is checked in and should be available on today's nightly build: typescript@next on npm. Can you give it a try and check if it resolves your issue?

@Tragetaschen
Copy link
Author

I'm running the version published to npm about 1 hour ago, if I understand the UTC timestamp correctly :-), but this doesn't fix this:

PS C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument> .\node_modules\.bin\tsc --version
Version 1.9.0-dev.20160302
PS C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument> .\node_modules\.bin\tsc -p App --diagnostics

<--- Last few GCs --->

   76343 ms: Scavenge 1405.2 (1503.3) -> 1405.2 (1503.3) MB, 39.1 / 0 ms (+ 63.0 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
   77758 ms: Mark-sweep 1405.2 (1503.3) -> 1402.6 (1503.3) MB, 1418.2 / 0 ms (+ 156.0 ms in 9 steps since start of marking, biggest step 63.0 ms) [last resort gc].
   79143 ms: Mark-sweep 1402.6 (1503.3) -> 1404.5 (1503.3) MB, 1385.3 / 0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 00000139B92E3AD1 <JS Object>
    2: objectTypeRelatedTo(aka objectTypeRelatedTo) [C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument\node_modules\typescript\lib\tsc.js:16258] [pc=000001D003672896] (this=00000139B9204189 <undefined>,source=0000036686D6E0D1 <a Type with map 0000022E6BEF0591>,originalSource=0000036686D6E
0D1 <a Type with map 0000022E6BEF0591>,target=000002659D08B0E1 <a Type with map 0000030B3616925...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

Again, casting the array members to <any> resolves the issue:

 PS C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument> .\node_modules\.bin\tsc -p App --diagnostics
Files:             466
Lines:           49743
Nodes:          192822
Identifiers:     69125
Symbols:      17619128
Types:           47239
Memory used:   152110K
I/O read:        0.02s
I/O write:       0.11s
Parse time:      0.84s
Bind time:       0.36s
Check time:      1.96s
Emit time:       0.52s
Total time:      3.69s

@Tragetaschen
Copy link
Author

Using 1.8.2 or today's next, I can force Typescript to consume additional 850MiB/800MiB of memory, by commenting out a single member:

import {BehaviorSubject} from 'rxjs/Rx';

class Foo extends BehaviorSubject<string> { }
class type {
    member: string; // remove me to gain 850MiB memory usage
}
class Bar extends BehaviorSubject<type> { }
var ARRAY = [Foo,Bar];

With member:

Memory used:    67709K
Parse time:      0.25s
Bind time:       0.15s
Check time:      0.75s

Without member:

Memory used:   920835K
Parse time:      0.33s
Bind time:       0.21s
Check time:     14.88s

@vladima
Copy link
Contributor

vladima commented Mar 2, 2016

I've checked and seems that today's @next ([email protected]) does not contain my changes. Can you retry using tsc.js that was built from master (I've pasted it here)

@Tragetaschen
Copy link
Author

Wheee!

PS C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument> .\node_modules\.bin\tsc --version
Version 1.9.0-dev.20160303
PS C:\Users\kairu\Source\Repos\Target-sg\App\src\App.Instrument> .\node_modules\.bin\tsc -p App --diagnostics
Files:             466
Lines:           49565
Nodes:          192343
Identifiers:     69004
Symbols:      17594575
Types:           47840
Memory used:   147710K
I/O read:        0.06s
I/O write:       0.09s
Parse time:      0.80s
Bind time:       0.37s
Check time:      2.27s
Emit time:       0.40s
Total time:      3.84s

I had to go back a few commits in my code to make it actually crash with 1.8.7. I had changed the contents of the offending array besides the <any> cast and it only took a large amount of memory instead of too much.

The 800MiB from my previous post have been reduced to 400MiB with this new nightly (70067K with member, 482524K without), so I'd guess there is still something left. Does this warrant a new bug?

I'd like to convince you (and @mhegazy) to put the fix in a service release. Not because it's hitting many people, but because the default Visual Studio experience (with Node 0.12.2) is just incredibly bad when you run into this and the changes in a code base are quite subtle to trigger it. Node 0.12.2 seems to not handle OOMs well and keeps running and VS just crashes out of thin air.

@mhegazy mhegazy modified the milestones: Salsa 1.9, TypeScript 2.0 Mar 3, 2016
@vladima
Copy link
Contributor

vladima commented Mar 3, 2016

#7372 ports this fix to the next point release

@Tragetaschen
Copy link
Author

Wonderful. Thanks!

@vladima vladima added the Fixed A PR has been merged for this issue label Mar 4, 2016
@vladima
Copy link
Contributor

vladima commented Mar 4, 2016

closing, since the fix is checked-in.

@vladima vladima closed this as completed Mar 4, 2016
@msklvsk
Copy link

msklvsk commented Mar 13, 2016

just killed a day with this problem (out of memory)
postponing angular update which requires rxjs beta.2, keeping angular on beta.6 until ts 1.8.9

@danielgerlag
Copy link
Member

+1

@danielgerlag
Copy link
Member

Ok, so I get this error using tsc 1.8.9 with Node 4 or Node 5.9, but not with Node 5.0

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants