Description
I'm running into very inconsistent memory use and compilation time when changing certain things in my code. A minor change in code can change my project from being compilable to causing out of memory issues and excessive build times.
TypeScript Version:
Tested with 1.7.5 and 1.8.9
rxjs 5.0.0-beta.2
Code
Variant 1:
import {Observable, ReplaySubject} from "rxjs/Rx";
export class Test {
constructor() {
// no types
const changes$ = new ReplaySubject<number>(1);
const editState$ = Observable.merge(Observable.of(true));
Observable.combineLatest(
editState$, changes$, // passed in as single arguments
(edit:boolean, id:number) => {
return {}
});
}
}
This compiles reasonably well, even though 1.7.5 is considerably faster:
Compiled with 1.7.5:
Files: 70
Lines: 25698
Nodes: 112017
Identifiers: 39588
Symbols: 53549
Types: 15397
I/O read: 0.17s
I/O write: 0.00s
Parse time: 0.57s
Bind time: 0.19s
Check time: 0.84s
Emit time: 0.02s
Total time: 1.62s
Compiled with 1.8.9
Files: 70
Lines: 25802
Nodes: 118578
Identifiers: 45679
Symbols: 1771501
Types: 13536
Memory used: 84667K
I/O read: 0.25s
I/O write: 0.02s
Parse time: 0.85s
Bind time: 0.55s
Check time: 1.67s
Emit time: 0.05s
Total time: 3.12s
Variant 2
Instead of passing the observables to Observable.combineLatest as single arguments, I chose to pass them in as an array:
import {Observable, ReplaySubject} from "rxjs/Rx";
export class Test {
constructor() {
// no types
const changes$ = new ReplaySubject<number>(1);
const editState$ = Observable.merge(Observable.of(true));
Observable.combineLatest(
[editState$, changes$], // passed in as array
(edit:boolean, id:number) => {
return {}
});
}
}
Now compilation is MUCH slower using way more memory:
Compiled with 1.7.5:
Files: 70
Lines: 25698
Nodes: 112018
Identifiers: 39588
Symbols: 649435
Types: 366854
I/O read: 0.19s
I/O write: 0.00s
Parse time: 0.62s
Bind time: 0.21s
Check time: 11.12s
Emit time: 0.03s
Total time: 11.98s <--
Compiled with 1.8.9
Files: 70
Lines: 25802
Nodes: 118579
Identifiers: 45679
Symbols: 2367311
Types: 364975
Memory used: 531080K <-- 531M vs 84M
I/O read: 0.03s
I/O write: 0.02s
Parse time: 0.66s
Bind time: 0.55s
Check time: 15.70s
Emit time: 0.08s
Total time: 16.98s <--
Variant 3
If I give the two constants explicit types, things change again:
import {Observable, ReplaySubject} from "rxjs/Rx";
export class Test {
constructor() {
// with types
const changes$:Observable<number> = new ReplaySubject<number>(1);
const editState$:Observable<boolean> = Observable.merge(Observable.of(true));
Observable.combineLatest(
[editState$, changes$], // passed in as array
(edit:boolean, id:number) => {
return {}
});
}
}
It's still not as efficient as variant 1, but at least comparable
Compiled with 1.7.5:
Files: 70
Lines: 25698
Nodes: 112024
Identifiers: 39590
Symbols: 95917
Types: 41030
I/O read: 0.16s
I/O write: 0.00s
Parse time: 0.56s
Bind time: 0.18s
Check time: 1.13s
Emit time: 0.03s
Total time: 1.90s
Compiled with 1.8.9
Files: 70
Lines: 25802
Nodes: 118585
Identifiers: 45681
Symbols: 1813809
Types: 39154
Memory used: 112982K
I/O read: 0.08s
I/O write: 0.01s
Parse time: 0.64s
Bind time: 0.53s
Check time: 2.44s
Emit time: 0.06s
Total time: 3.67s
tsconfig.json used in all cases:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": false
},
"exclude": [
"node_modules",
"typings/main.d.ts",
"typings/main"
]
}
Typings
{
"dependencies": {
"es6-promise": "github:typed-typings/npm-es6-promise#fb04188767acfec1defd054fc8024fafa5cd4de7"
},
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c"
}
}
Is this expected behavior? Is there a way to get more consistent results?
P.S.: checked with 1.9.0-dev.20160321 with similar results.