perf(compiler): don’t emit summaries for jit by default
This re-adds the flag `enableSummariesForJit` to the compiler options that already existed in Angular 4.
This commit is contained in:
parent
0038712474
commit
b0868915ae
packages
bazel/src
compiler-cli
integrationtest
src/transformers
test
compiler/src/aot
@ -71,6 +71,7 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs):
|
|||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"generateCodeForLibraries": False,
|
"generateCodeForLibraries": False,
|
||||||
"allowEmptyCodegenFiles": True,
|
"allowEmptyCodegenFiles": True,
|
||||||
|
"enableSummariesforJit": True,
|
||||||
# FIXME: wrong place to de-dupe
|
# FIXME: wrong place to de-dupe
|
||||||
"expectedOut": depset([o.path for o in expected_outs]).to_list()
|
"expectedOut": depset([o.path for o in expected_outs]).to_list()
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
// For TypeScript 1.8, we have to lay out generated files
|
// For TypeScript 1.8, we have to lay out generated files
|
||||||
// in the same source directory with your code.
|
// in the same source directory with your code.
|
||||||
"genDir": ".",
|
"genDir": ".",
|
||||||
"debug": true
|
"debug": true,
|
||||||
|
"enableSummariesForJit": true
|
||||||
},
|
},
|
||||||
|
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
@ -144,6 +144,12 @@ export interface CompilerOptions extends ts.CompilerOptions {
|
|||||||
|
|
||||||
/** generate all possible generated files */
|
/** generate all possible generated files */
|
||||||
allowEmptyCodegenFiles?: boolean;
|
allowEmptyCodegenFiles?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to generate .ngsummary.ts files that allow to use AOTed artifacts
|
||||||
|
* in JIT mode. This is off by default.
|
||||||
|
*/
|
||||||
|
enableSummariesForJit?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CompilerHost extends ts.CompilerHost {
|
export interface CompilerHost extends ts.CompilerHost {
|
||||||
|
@ -533,7 +533,7 @@ function getAotCompilerOptions(options: CompilerOptions): AotCompilerOptions {
|
|||||||
locale: options.i18nInLocale,
|
locale: options.i18nInLocale,
|
||||||
i18nFormat: options.i18nInFormat || options.i18nOutFormat, translations, missingTranslation,
|
i18nFormat: options.i18nInFormat || options.i18nOutFormat, translations, missingTranslation,
|
||||||
enableLegacyTemplate: options.enableLegacyTemplate,
|
enableLegacyTemplate: options.enableLegacyTemplate,
|
||||||
enableSummariesForJit: true,
|
enableSummariesForJit: options.enableSummariesForJit,
|
||||||
preserveWhitespaces: options.preserveWhitespaces,
|
preserveWhitespaces: options.preserveWhitespaces,
|
||||||
fullTemplateTypeCheck: options.fullTemplateTypeCheck,
|
fullTemplateTypeCheck: options.fullTemplateTypeCheck,
|
||||||
allowEmptyCodegenFiles: options.allowEmptyCodegenFiles,
|
allowEmptyCodegenFiles: options.allowEmptyCodegenFiles,
|
||||||
|
@ -336,18 +336,21 @@ describe('ngc transformer command-line', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function expectAllGeneratedFilesToExist() {
|
function expectAllGeneratedFilesToExist(enableSummariesForJit = true) {
|
||||||
modules.forEach(moduleName => {
|
modules.forEach(moduleName => {
|
||||||
if (/module|comp/.test(moduleName)) {
|
if (/module|comp/.test(moduleName)) {
|
||||||
shouldExist(moduleName + '.ngfactory.js');
|
shouldExist(moduleName + '.ngfactory.js');
|
||||||
shouldExist(moduleName + '.ngfactory.d.ts');
|
shouldExist(moduleName + '.ngfactory.d.ts');
|
||||||
shouldExist(moduleName + '.ngsummary.js');
|
|
||||||
shouldExist(moduleName + '.ngsummary.d.ts');
|
|
||||||
} else {
|
} else {
|
||||||
shouldNotExist(moduleName + '.ngfactory.js');
|
shouldNotExist(moduleName + '.ngfactory.js');
|
||||||
shouldNotExist(moduleName + '.ngfactory.d.ts');
|
shouldNotExist(moduleName + '.ngfactory.d.ts');
|
||||||
|
}
|
||||||
|
if (enableSummariesForJit) {
|
||||||
shouldExist(moduleName + '.ngsummary.js');
|
shouldExist(moduleName + '.ngsummary.js');
|
||||||
shouldExist(moduleName + '.ngsummary.d.ts');
|
shouldExist(moduleName + '.ngsummary.d.ts');
|
||||||
|
} else {
|
||||||
|
shouldNotExist(moduleName + '.ngsummary.js');
|
||||||
|
shouldNotExist(moduleName + '.ngsummary.d.ts');
|
||||||
}
|
}
|
||||||
shouldExist(moduleName + '.ngsummary.json');
|
shouldExist(moduleName + '.ngsummary.json');
|
||||||
shouldNotExist(moduleName + '.ngfactory.metadata.json');
|
shouldNotExist(moduleName + '.ngfactory.metadata.json');
|
||||||
@ -359,10 +362,11 @@ describe('ngc transformer command-line', () => {
|
|||||||
shouldExist('emulated.css.shim.ngstyle.d.ts');
|
shouldExist('emulated.css.shim.ngstyle.d.ts');
|
||||||
}
|
}
|
||||||
|
|
||||||
it('should emit generated files from sources', () => {
|
it('should emit generated files from sources with summariesForJit', () => {
|
||||||
writeConfig(`{
|
writeConfig(`{
|
||||||
"extends": "./tsconfig-base.json",
|
"extends": "./tsconfig-base.json",
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
|
"enableSummariesForJit": true
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts"]
|
"include": ["src/**/*.ts"]
|
||||||
}`);
|
}`);
|
||||||
@ -370,7 +374,22 @@ describe('ngc transformer command-line', () => {
|
|||||||
expect(exitCode).toEqual(0);
|
expect(exitCode).toEqual(0);
|
||||||
outDir = path.resolve(basePath, 'built', 'src');
|
outDir = path.resolve(basePath, 'built', 'src');
|
||||||
expectJsDtsMetadataJsonToExist();
|
expectJsDtsMetadataJsonToExist();
|
||||||
expectAllGeneratedFilesToExist();
|
expectAllGeneratedFilesToExist(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not emit generated files from sources without summariesForJit', () => {
|
||||||
|
writeConfig(`{
|
||||||
|
"extends": "./tsconfig-base.json",
|
||||||
|
"angularCompilerOptions": {
|
||||||
|
"enableSummariesForJit": false
|
||||||
|
},
|
||||||
|
"include": ["src/**/*.ts"]
|
||||||
|
}`);
|
||||||
|
const exitCode = main(['-p', path.join(basePath, 'tsconfig.json')], errorSpy);
|
||||||
|
expect(exitCode).toEqual(0);
|
||||||
|
outDir = path.resolve(basePath, 'built', 'src');
|
||||||
|
expectJsDtsMetadataJsonToExist();
|
||||||
|
expectAllGeneratedFilesToExist(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit generated files from libraries', () => {
|
it('should emit generated files from libraries', () => {
|
||||||
@ -408,7 +427,8 @@ describe('ngc transformer command-line', () => {
|
|||||||
writeConfig(`{
|
writeConfig(`{
|
||||||
"extends": "./tsconfig-base.json",
|
"extends": "./tsconfig-base.json",
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"skipTemplateCodegen": false
|
"skipTemplateCodegen": false,
|
||||||
|
"enableSummariesForJit": true
|
||||||
},
|
},
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "built"
|
"outDir": "built"
|
||||||
@ -880,7 +900,8 @@ describe('ngc transformer command-line', () => {
|
|||||||
write('tsconfig-ng.json', `{
|
write('tsconfig-ng.json', `{
|
||||||
"extends": "./tsconfig-base.json",
|
"extends": "./tsconfig-base.json",
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"generateCodeForLibraries": true
|
"generateCodeForLibraries": true,
|
||||||
|
"enableSummariesForJit": true
|
||||||
},
|
},
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "."
|
"outDir": "."
|
||||||
@ -896,7 +917,8 @@ describe('ngc transformer command-line', () => {
|
|||||||
write('lib1/tsconfig-lib1.json', `{
|
write('lib1/tsconfig-lib1.json', `{
|
||||||
"extends": "../tsconfig-base.json",
|
"extends": "../tsconfig-base.json",
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"generateCodeForLibraries": false
|
"generateCodeForLibraries": false,
|
||||||
|
"enableSummariesForJit": true
|
||||||
},
|
},
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
@ -919,7 +941,8 @@ describe('ngc transformer command-line', () => {
|
|||||||
write('lib2/tsconfig-lib2.json', `{
|
write('lib2/tsconfig-lib2.json', `{
|
||||||
"extends": "../tsconfig-base.json",
|
"extends": "../tsconfig-base.json",
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"generateCodeForLibraries": false
|
"generateCodeForLibraries": false,
|
||||||
|
"enableSummariesForJit": true
|
||||||
},
|
},
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
@ -941,7 +964,8 @@ describe('ngc transformer command-line', () => {
|
|||||||
write('app/tsconfig-app.json', `{
|
write('app/tsconfig-app.json', `{
|
||||||
"extends": "../tsconfig-base.json",
|
"extends": "../tsconfig-base.json",
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"generateCodeForLibraries": false
|
"generateCodeForLibraries": false,
|
||||||
|
"enableSummariesForJit": true
|
||||||
},
|
},
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
|
@ -300,7 +300,10 @@ describe('ng program', () => {
|
|||||||
export * from './main';
|
export * from './main';
|
||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
const options = testSupport.createCompilerOptions({allowEmptyCodegenFiles: true});
|
const options = testSupport.createCompilerOptions({
|
||||||
|
allowEmptyCodegenFiles: true,
|
||||||
|
enableSummariesForJit: true,
|
||||||
|
});
|
||||||
const host = ng.createCompilerHost({options});
|
const host = ng.createCompilerHost({options});
|
||||||
const written = new Map < string, {
|
const written = new Map < string, {
|
||||||
original: ts.SourceFile[]|undefined;
|
original: ts.SourceFile[]|undefined;
|
||||||
@ -384,11 +387,11 @@ describe('ng program', () => {
|
|||||||
testSupport.shouldExist('built/main.ngfactory.js');
|
testSupport.shouldExist('built/main.ngfactory.js');
|
||||||
testSupport.shouldExist('built/main.ngfactory.d.ts');
|
testSupport.shouldExist('built/main.ngfactory.d.ts');
|
||||||
testSupport.shouldExist('built/main.ngsummary.json');
|
testSupport.shouldExist('built/main.ngsummary.json');
|
||||||
testSupport.shouldNotExist('build/node_modules/lib/index.js');
|
testSupport.shouldNotExist('built/node_modules/lib/index.js');
|
||||||
testSupport.shouldNotExist('build/node_modules/lib/index.d.ts');
|
testSupport.shouldNotExist('built/node_modules/lib/index.d.ts');
|
||||||
testSupport.shouldNotExist('build/node_modules/lib/index.ngfactory.js');
|
testSupport.shouldNotExist('built/node_modules/lib/index.ngfactory.js');
|
||||||
testSupport.shouldNotExist('build/node_modules/lib/index.ngfactory.d.ts');
|
testSupport.shouldNotExist('built/node_modules/lib/index.ngfactory.d.ts');
|
||||||
testSupport.shouldNotExist('build/node_modules/lib/index.ngsummary.json');
|
testSupport.shouldNotExist('built/node_modules/lib/index.ngsummary.json');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createSrcToOutPathMapper', () => {
|
describe('createSrcToOutPathMapper', () => {
|
||||||
|
@ -98,7 +98,9 @@ export class AotCompiler {
|
|||||||
if (this._options.allowEmptyCodegenFiles || file.directives.length || file.pipes.length ||
|
if (this._options.allowEmptyCodegenFiles || file.directives.length || file.pipes.length ||
|
||||||
file.injectables.length || file.ngModules.length || file.exportsNonSourceFiles) {
|
file.injectables.length || file.ngModules.length || file.exportsNonSourceFiles) {
|
||||||
genFileNames.push(ngfactoryFilePath(file.fileName, true));
|
genFileNames.push(ngfactoryFilePath(file.fileName, true));
|
||||||
genFileNames.push(summaryForJitFileName(file.fileName, true));
|
if (this._options.enableSummariesForJit) {
|
||||||
|
genFileNames.push(summaryForJitFileName(file.fileName, true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const fileSuffix = splitTypescriptSuffix(file.fileName, true)[1];
|
const fileSuffix = splitTypescriptSuffix(file.fileName, true)[1];
|
||||||
file.directives.forEach((dirSymbol) => {
|
file.directives.forEach((dirSymbol) => {
|
||||||
@ -376,7 +378,9 @@ export class AotCompiler {
|
|||||||
metadata: this._metadataResolver.getInjectableSummary(ref) !.type
|
metadata: this._metadataResolver.getInjectableSummary(ref) !.type
|
||||||
}))
|
}))
|
||||||
];
|
];
|
||||||
const forJitOutputCtx = this._createOutputContext(summaryForJitFileName(srcFileName, true));
|
const forJitOutputCtx = this._options.enableSummariesForJit ?
|
||||||
|
this._createOutputContext(summaryForJitFileName(srcFileName, true)) :
|
||||||
|
null;
|
||||||
const {json, exportAs} = serializeSummaries(
|
const {json, exportAs} = serializeSummaries(
|
||||||
srcFileName, forJitOutputCtx, this._summaryResolver, this._symbolResolver, symbolSummaries,
|
srcFileName, forJitOutputCtx, this._summaryResolver, this._symbolResolver, symbolSummaries,
|
||||||
typeData);
|
typeData);
|
||||||
@ -387,11 +391,11 @@ export class AotCompiler {
|
|||||||
]));
|
]));
|
||||||
});
|
});
|
||||||
const summaryJson = new GeneratedFile(srcFileName, summaryFileName(srcFileName), json);
|
const summaryJson = new GeneratedFile(srcFileName, summaryFileName(srcFileName), json);
|
||||||
if (this._options.enableSummariesForJit) {
|
const result = [summaryJson];
|
||||||
return [summaryJson, this._codegenSourceModule(srcFileName, forJitOutputCtx)];
|
if (forJitOutputCtx) {
|
||||||
|
result.push(this._codegenSourceModule(srcFileName, forJitOutputCtx));
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
return [summaryJson];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _compileModule(outputCtx: OutputContext, ngModule: CompileNgModuleMetadata): void {
|
private _compileModule(outputCtx: OutputContext, ngModule: CompileNgModuleMetadata): void {
|
||||||
|
@ -14,7 +14,6 @@ export interface AotCompilerOptions {
|
|||||||
translations?: string;
|
translations?: string;
|
||||||
missingTranslation?: MissingTranslationStrategy;
|
missingTranslation?: MissingTranslationStrategy;
|
||||||
enableLegacyTemplate?: boolean;
|
enableLegacyTemplate?: boolean;
|
||||||
/** TODO(tbosch): remove this flag as it is always on in the new ngc */
|
|
||||||
enableSummariesForJit?: boolean;
|
enableSummariesForJit?: boolean;
|
||||||
preserveWhitespaces?: boolean;
|
preserveWhitespaces?: boolean;
|
||||||
fullTemplateTypeCheck?: boolean;
|
fullTemplateTypeCheck?: boolean;
|
||||||
|
@ -15,14 +15,14 @@ import {ResolvedStaticSymbol, StaticSymbolResolver} from './static_symbol_resolv
|
|||||||
import {summaryForJitFileName, summaryForJitName} from './util';
|
import {summaryForJitFileName, summaryForJitName} from './util';
|
||||||
|
|
||||||
export function serializeSummaries(
|
export function serializeSummaries(
|
||||||
srcFileName: string, forJitCtx: OutputContext, summaryResolver: SummaryResolver<StaticSymbol>,
|
srcFileName: string, forJitCtx: OutputContext | null,
|
||||||
symbolResolver: StaticSymbolResolver, symbols: ResolvedStaticSymbol[], types: {
|
summaryResolver: SummaryResolver<StaticSymbol>, symbolResolver: StaticSymbolResolver,
|
||||||
|
symbols: ResolvedStaticSymbol[], types: {
|
||||||
summary: CompileTypeSummary,
|
summary: CompileTypeSummary,
|
||||||
metadata: CompileNgModuleMetadata | CompileDirectiveMetadata | CompilePipeMetadata |
|
metadata: CompileNgModuleMetadata | CompileDirectiveMetadata | CompilePipeMetadata |
|
||||||
CompileTypeMetadata
|
CompileTypeMetadata
|
||||||
}[]): {json: string, exportAs: {symbol: StaticSymbol, exportAs: string}[]} {
|
}[]): {json: string, exportAs: {symbol: StaticSymbol, exportAs: string}[]} {
|
||||||
const toJsonSerializer = new ToJsonSerializer(symbolResolver, summaryResolver, srcFileName);
|
const toJsonSerializer = new ToJsonSerializer(symbolResolver, summaryResolver, srcFileName);
|
||||||
const forJitSerializer = new ForJitSerializer(forJitCtx, symbolResolver);
|
|
||||||
|
|
||||||
// for symbols, we use everything except for the class metadata itself
|
// for symbols, we use everything except for the class metadata itself
|
||||||
// (we keep the statics though), as the class metadata is contained in the
|
// (we keep the statics though), as the class metadata is contained in the
|
||||||
@ -33,18 +33,20 @@ export function serializeSummaries(
|
|||||||
|
|
||||||
// Add type summaries.
|
// Add type summaries.
|
||||||
types.forEach(({summary, metadata}) => {
|
types.forEach(({summary, metadata}) => {
|
||||||
forJitSerializer.addSourceType(summary, metadata);
|
|
||||||
toJsonSerializer.addSummary(
|
toJsonSerializer.addSummary(
|
||||||
{symbol: summary.type.reference, metadata: undefined, type: summary});
|
{symbol: summary.type.reference, metadata: undefined, type: summary});
|
||||||
});
|
});
|
||||||
toJsonSerializer.unprocessedSymbolSummariesBySymbol.forEach((summary) => {
|
|
||||||
if (summaryResolver.isLibraryFile(summary.symbol.filePath) && summary.type) {
|
|
||||||
forJitSerializer.addLibType(summary.type);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const {json, exportAs} = toJsonSerializer.serialize();
|
const {json, exportAs} = toJsonSerializer.serialize();
|
||||||
forJitSerializer.serialize(exportAs);
|
if (forJitCtx) {
|
||||||
|
const forJitSerializer = new ForJitSerializer(forJitCtx, symbolResolver);
|
||||||
|
types.forEach(({summary, metadata}) => { forJitSerializer.addSourceType(summary, metadata); });
|
||||||
|
toJsonSerializer.unprocessedSymbolSummariesBySymbol.forEach((summary) => {
|
||||||
|
if (summaryResolver.isLibraryFile(summary.symbol.filePath) && summary.type) {
|
||||||
|
forJitSerializer.addLibType(summary.type);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
forJitSerializer.serialize(exportAs);
|
||||||
|
}
|
||||||
return {json, exportAs};
|
return {json, exportAs};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user