@@ -24,6 +24,7 @@ import {
24
24
registerLocaleData ,
25
25
replaceResources ,
26
26
} from './transformers' ;
27
+ import { time , timeEnd } from './benchmark' ;
27
28
28
29
// These imports do not exist on Angular versions lower than 5, so we cannot use a static ES6
29
30
// import. Instead we copy their types into './ngtools_api2.d.ts'.
@@ -300,29 +301,36 @@ export class AngularCompilerPlugin implements Tapable {
300
301
301
302
if ( this . _JitMode ) {
302
303
// Create the TypeScript program.
304
+ time ( '_createOrUpdateProgram.ts.createProgram' ) ;
303
305
this . _program = ts . createProgram (
304
306
this . _tsFilenames ,
305
307
this . _angularCompilerOptions ,
306
308
this . _angularCompilerHost ,
307
309
this . _program
308
310
) as ts . Program & Program ;
311
+ timeEnd ( '_createOrUpdateProgram.ts.createProgram' ) ;
309
312
310
313
return Promise . resolve ( ) ;
311
314
} else {
315
+ time ( '_createOrUpdateProgram.ng.createProgram' ) ;
312
316
// Create the Angular program.
313
317
this . _program = createProgram ( {
314
318
rootNames : this . _tsFilenames ,
315
319
options : this . _angularCompilerOptions ,
316
320
host : this . _angularCompilerHost ,
317
321
oldProgram : this . _program
318
322
} ) as ts . Program & Program ;
323
+ timeEnd ( '_createOrUpdateProgram.ng.createProgram' ) ;
319
324
320
- return this . _program . loadNgStructureAsync ( ) ;
325
+ time ( '_createOrUpdateProgram.ng.loadNgStructureAsync' ) ;
326
+ return this . _program . loadNgStructureAsync ( )
327
+ . then ( ( ) => timeEnd ( '_createOrUpdateProgram.ng.loadNgStructureAsync' ) ) ;
321
328
}
322
329
}
323
330
324
331
private _getLazyRoutesFromNgtools ( ) {
325
332
try {
333
+ time ( '_getLazyRoutesFromNgtools' ) ;
326
334
const result = __NGTOOLS_PRIVATE_API_2 . listLazyRoutes ( {
327
335
program : this . _getTsProgram ( ) ,
328
336
host : this . _compilerHost ,
@@ -332,6 +340,7 @@ export class AngularCompilerPlugin implements Tapable {
332
340
} ) ,
333
341
entryModule : this . _entryModule
334
342
} ) ;
343
+ timeEnd ( '_getLazyRoutesFromNgtools' ) ;
335
344
return result ;
336
345
} catch ( err ) {
337
346
// We silence the error that the @angular /router could not be found. In that case, there is
@@ -345,6 +354,7 @@ export class AngularCompilerPlugin implements Tapable {
345
354
}
346
355
347
356
private _findLazyRoutesInAst ( changedFilePaths : string [ ] ) : LazyRouteMap {
357
+ time ( '_findLazyRoutesInAst' ) ;
348
358
const result : LazyRouteMap = Object . create ( null ) ;
349
359
for ( const filePath of changedFilePaths ) {
350
360
const fileLazyRoutes = findLazyRoutes ( filePath , this . _compilerHost , undefined ,
@@ -354,6 +364,7 @@ export class AngularCompilerPlugin implements Tapable {
354
364
result [ routeKey ] = route ;
355
365
}
356
366
}
367
+ timeEnd ( '_findLazyRoutesInAst' ) ;
357
368
return result ;
358
369
}
359
370
@@ -508,6 +519,7 @@ export class AngularCompilerPlugin implements Tapable {
508
519
}
509
520
510
521
private _make ( compilation : any , cb : ( err ?: any , request ?: any ) => void ) {
522
+ time ( '_make' ) ;
511
523
this . _compilation = compilation ;
512
524
if ( this . _compilation . _ngToolsWebpackPluginInstance ) {
513
525
return cb ( new Error ( 'An @ngtools/webpack plugin already exist for this compilation.' ) ) ;
@@ -516,8 +528,10 @@ export class AngularCompilerPlugin implements Tapable {
516
528
this . _compilation . _ngToolsWebpackPluginInstance = this ;
517
529
518
530
// Create the resource loader with the webpack compilation.
531
+ time ( '_make.setResourceLoader' ) ;
519
532
const resourceLoader = new WebpackResourceLoader ( compilation ) ;
520
533
this . _compilerHost . setResourceLoader ( resourceLoader ) ;
534
+ timeEnd ( '_make.setResourceLoader' ) ;
521
535
522
536
this . _donePromise = Promise . resolve ( )
523
537
. then ( ( ) => {
@@ -532,26 +546,31 @@ export class AngularCompilerPlugin implements Tapable {
532
546
. then ( ( ) => {
533
547
// If there's still no entryModule try to resolve from mainPath.
534
548
if ( ! this . _entryModule && this . _options . mainPath ) {
549
+ time ( '_make.resolveEntryModuleFromMain' ) ;
535
550
const mainPath = path . resolve ( this . _basePath , this . _options . mainPath ) ;
536
551
this . _entryModule = resolveEntryModuleFromMain (
537
552
mainPath , this . _compilerHost , this . _getTsProgram ( ) ) ;
553
+ timeEnd ( '_make.resolveEntryModuleFromMain' ) ;
538
554
}
539
555
} ) ;
540
556
}
541
557
} )
542
558
. then ( ( ) => this . _update ( ) )
543
559
. then ( ( ) => {
560
+ timeEnd ( '_make' ) ;
544
561
cb ( ) ;
545
562
} , ( err : any ) => {
546
563
this . _failedCompilation = true ;
547
564
compilation . errors . push ( err . stack ) ;
565
+ timeEnd ( '_make' ) ;
548
566
cb ( ) ;
549
567
} ) ;
550
568
}
551
569
552
570
private _update ( ) {
553
571
// We only want to update on TS and template changes, but all kinds of files are on this
554
572
// list, like package.json and .ngsummary.json files.
573
+ time ( '_update' ) ;
555
574
let changedFiles = this . _compilerHost . getChangedFilePaths ( )
556
575
. filter ( k => / ( t s | h t m l | c s s | s c s s | s a s s | l e s s | s t y l ) / . test ( k ) ) ;
557
576
@@ -580,6 +599,7 @@ export class AngularCompilerPlugin implements Tapable {
580
599
if ( changedFiles . length > 0 || this . _firstRun ) {
581
600
582
601
// Go through each changed file and add transforms as needed.
602
+ time ( '_update.transformOps' ) ;
583
603
const sourceFiles = this . _getChangedTsFiles ( ) . map ( ( fileName ) => {
584
604
const sourceFile = this . _getTsProgram ( ) . getSourceFile ( fileName ) ;
585
605
if ( ! sourceFile ) {
@@ -627,13 +647,18 @@ export class AngularCompilerPlugin implements Tapable {
627
647
for ( let fileTransformOps of this . _transformMap . values ( ) ) {
628
648
transformOps . push ( ...fileTransformOps ) ;
629
649
}
650
+ timeEnd ( '_update.transformOps' ) ;
630
651
652
+ time ( '_update.makeTransform' ) ;
631
653
const transformers : CustomTransformers = {
632
654
beforeTs : transformOps . length > 0 ? [ makeTransform ( transformOps ) ] : [ ]
633
655
} ;
656
+ timeEnd ( '_update.makeTransform' ) ;
634
657
635
658
// Emit files.
659
+ time ( '_update._emit' ) ;
636
660
const { emitResult, diagnostics } = this . _emit ( sourceFiles , transformers ) ;
661
+ timeEnd ( '_update._emit' ) ;
637
662
638
663
// Report diagnostics.
639
664
// TODO: check if the old _translateSourceMap function is needed.
@@ -659,6 +684,7 @@ export class AngularCompilerPlugin implements Tapable {
659
684
this . _failedCompilation = true ;
660
685
}
661
686
}
687
+ timeEnd ( '_update' ) ;
662
688
} ) ;
663
689
}
664
690
@@ -678,6 +704,7 @@ export class AngularCompilerPlugin implements Tapable {
678
704
sourceFiles : ts . SourceFile [ ] ,
679
705
customTransformers : ts . CustomTransformers & CustomTransformers
680
706
) {
707
+ time ( '_emit' ) ;
681
708
const program = this . _program ;
682
709
const allDiagnostics : Diagnostics = [ ] ;
683
710
@@ -697,48 +724,68 @@ export class AngularCompilerPlugin implements Tapable {
697
724
const tsProgram : ts . Program = program ;
698
725
699
726
// Check parameter diagnostics.
727
+ // TODO: check this only on initial program creation.
728
+ time ( '_emit.ts.getOptionsDiagnostics' ) ;
700
729
shouldEmit = shouldEmit && checkDiagnostics ( tsProgram . getOptionsDiagnostics ( ) ) ;
730
+ timeEnd ( '_emit.ts.getOptionsDiagnostics' ) ;
701
731
702
732
// Check syntactic diagnostics.
733
+ time ( '_emit.ts.getSyntacticDiagnostics' ) ;
703
734
shouldEmit = shouldEmit && checkDiagnostics ( tsProgram . getSyntacticDiagnostics ( ) ) ;
735
+ timeEnd ( '_emit.ts.getSyntacticDiagnostics' ) ;
704
736
705
737
// Check semantic diagnostics.
738
+ time ( '_emit.ts.getSemanticDiagnostics' ) ;
706
739
shouldEmit = shouldEmit && checkDiagnostics ( tsProgram . getSemanticDiagnostics ( ) ) ;
740
+ timeEnd ( '_emit.ts.getSemanticDiagnostics' ) ;
707
741
708
742
if ( shouldEmit ) {
709
743
sourceFiles . forEach ( ( sf ) => {
744
+ const timeLabel = `_emit.ts+${ sf . fileName } +.emit` ;
745
+ time ( timeLabel ) ;
710
746
emitResult = tsProgram . emit ( sf , undefined , undefined , undefined ,
711
747
{ before : customTransformers . beforeTs }
712
748
) ;
713
749
allDiagnostics . push ( ...emitResult . diagnostics ) ;
750
+ timeEnd ( timeLabel ) ;
714
751
} ) ;
715
752
}
716
753
} else {
717
754
const angularProgram : Program = program ;
718
755
719
756
// Check parameter diagnostics.
757
+ // TODO: check this only on initial program creation.
758
+ time ( '_emit.ng.getTsOptionDiagnostics+getNgOptionDiagnostics' ) ;
720
759
shouldEmit = shouldEmit && checkDiagnostics ( [
721
760
...angularProgram . getTsOptionDiagnostics ( ) , ...angularProgram . getNgOptionDiagnostics ( )
722
761
] ) ;
762
+ timeEnd ( '_emit.ng.getTsOptionDiagnostics+getNgOptionDiagnostics' ) ;
723
763
724
764
// Check syntactic diagnostics.
765
+ time ( '_emit.ng.getTsSyntacticDiagnostics' ) ;
725
766
shouldEmit = shouldEmit && checkDiagnostics ( angularProgram . getTsSyntacticDiagnostics ( ) ) ;
767
+ timeEnd ( '_emit.ng.getTsSyntacticDiagnostics' ) ;
726
768
727
769
// Check TypeScript semantic and Angular structure diagnostics.
770
+ time ( '_emit.ng.getTsSemanticDiagnostics+getNgStructuralDiagnostics' ) ;
728
771
shouldEmit = shouldEmit && checkDiagnostics (
729
772
[ ...angularProgram . getTsSemanticDiagnostics ( ) ,
730
773
...angularProgram . getNgStructuralDiagnostics ( )
731
774
] ) ;
775
+ timeEnd ( '_emit.ng.getTsSemanticDiagnostics+getNgStructuralDiagnostics' ) ;
732
776
733
777
// Check Angular semantic diagnostics
734
778
shouldEmit = shouldEmit && checkDiagnostics ( angularProgram . getNgSemanticDiagnostics ( ) ) ;
735
779
736
780
if ( shouldEmit ) {
781
+ time ( '_emit.ng.emit' ) ;
737
782
emitResult = angularProgram . emit ( { emitFlags : EmitFlags . Default , customTransformers } ) ;
738
783
allDiagnostics . push ( ...emitResult . diagnostics ) ;
784
+ timeEnd ( '_emit.ng.emit' ) ;
739
785
}
740
786
}
741
787
} catch ( e ) {
788
+ time ( '_emit.catch' ) ;
742
789
// This function is available in the import below, but this way we avoid the dependency.
743
790
// import { isSyntaxError } from '@angular/compiler';
744
791
function isSyntaxError ( error : Error ) : boolean {
@@ -759,7 +806,9 @@ export class AngularCompilerPlugin implements Tapable {
759
806
}
760
807
allDiagnostics . push (
761
808
{ category : ts . DiagnosticCategory . Error , messageText : errMsg , code, source : SOURCE } ) ;
809
+ timeEnd ( '_emit.catch' ) ;
762
810
}
811
+ timeEnd ( '_emit' ) ;
763
812
return { program, emitResult, diagnostics : allDiagnostics } ;
764
813
}
765
814
}
0 commit comments