Skip to content

Commit 01264ac

Browse files
Reducing tsbuildinfo size further (#43695)
* Serialize compiler options that are needed from old state when creating new state * Dont write affectsGlobalScope if not true * Encode FileInfo for better serialization size * Update src/compiler/builder.ts Co-authored-by: TypeScript Bot <[email protected]>
1 parent 9af763d commit 01264ac

File tree

182 files changed

+3084
-6388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+3084
-6388
lines changed

src/compiler/builder.ts

+47-17
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,23 @@ namespace ts {
708708
export type ProgramBuildInfoDiagnostic = number | [fileId: number, diagnostics: readonly ReusableDiagnostic[]];
709709
export type ProgramBuilderInfoFilePendingEmit = [fileId: number, emitKind: BuilderFileEmit];
710710
export type ProgramBuildInfoReferencedMap = [fileId: number, fileIdListId: number][];
711+
export type ProgramBuildInfoBuilderStateFileInfo = Omit<BuilderState.FileInfo, "signature"> & {
712+
/**
713+
* Signature is
714+
* - undefined if FileInfo.version === FileInfo.signature
715+
* - false if FileInfo has signature as undefined (not calculated)
716+
* - string actual signature
717+
*/
718+
signature: string | false | undefined;
719+
};
720+
/**
721+
* ProgramBuildInfoFileInfo is string if FileInfo.version === FileInfo.signature && !FileInfo.affectsGlobalScope otherwise encoded FileInfo
722+
*/
723+
export type ProgramBuildInfoFileInfo = string | ProgramBuildInfoBuilderStateFileInfo;
711724
export interface ProgramBuildInfo {
712725
fileNames: readonly string[];
713-
fileInfos: readonly BuilderState.FileInfo[];
714-
options: CompilerOptions;
726+
fileInfos: readonly ProgramBuildInfoFileInfo[];
727+
options: CompilerOptions | undefined;
715728
fileIdsList?: readonly (readonly number[])[];
716729
referencedMap?: ProgramBuildInfoReferencedMap;
717730
exportedModulesMap?: ProgramBuildInfoReferencedMap;
@@ -730,12 +743,21 @@ namespace ts {
730743
const fileNameToFileId = new Map<string, number>();
731744
let fileIdsList: (readonly number[])[] | undefined;
732745
let fileNamesToFileIdListId: ESMap<string, number> | undefined;
733-
const fileInfos = arrayFrom(state.fileInfos.entries(), ([key, value]) => {
746+
const fileInfos = arrayFrom(state.fileInfos.entries(), ([key, value]): ProgramBuildInfoFileInfo => {
734747
// Ensure fileId
735748
const fileId = toFileId(key);
736749
Debug.assert(fileNames[fileId - 1] === relativeToBuildInfo(key));
737750
const signature = state.currentAffectedFilesSignatures && state.currentAffectedFilesSignatures.get(key);
738-
return signature === undefined ? value : { version: value.version, signature, affectsGlobalScope: value.affectsGlobalScope };
751+
const actualSignature = signature ?? value.signature;
752+
return value.version === actualSignature ?
753+
value.affectsGlobalScope ?
754+
{ version: value.version, signature: undefined, affectsGlobalScope: true } :
755+
value.version :
756+
actualSignature !== undefined ?
757+
signature === undefined ?
758+
value :
759+
{ version: value.version, signature, affectsGlobalScope: value.affectsGlobalScope } :
760+
{ version: value.version, signature: false, affectsGlobalScope: value.affectsGlobalScope };
739761
});
740762

741763
let referencedMap: ProgramBuildInfoReferencedMap | undefined;
@@ -787,7 +809,7 @@ namespace ts {
787809
return {
788810
fileNames,
789811
fileInfos,
790-
options: convertToReusableCompilerOptions(state.compilerOptions, relativeToBuildInfoEnsuringAbsolutePath),
812+
options: convertToProgramBuildInfoCompilerOptions(state.compilerOptions, relativeToBuildInfoEnsuringAbsolutePath),
791813
fileIdsList,
792814
referencedMap,
793815
exportedModulesMap,
@@ -824,19 +846,19 @@ namespace ts {
824846
}
825847
}
826848

827-
function convertToReusableCompilerOptions(options: CompilerOptions, relativeToBuildInfo: (path: string) => string) {
828-
const result: CompilerOptions = {};
849+
function convertToProgramBuildInfoCompilerOptions(options: CompilerOptions, relativeToBuildInfo: (path: string) => string) {
850+
let result: CompilerOptions | undefined;
829851
const { optionsNameMap } = getOptionsNameMap();
830852

831853
for (const name of getOwnKeys(options).sort(compareStringsCaseSensitive)) {
832-
result[name] = convertToReusableCompilerOptionValue(
833-
optionsNameMap.get(name.toLowerCase()),
834-
options[name] as CompilerOptionsValue,
835-
relativeToBuildInfo
836-
);
837-
}
838-
if (result.configFilePath) {
839-
result.configFilePath = relativeToBuildInfo(result.configFilePath);
854+
const optionInfo = optionsNameMap.get(name.toLowerCase());
855+
if (optionInfo?.affectsEmit || optionInfo?.affectsSemanticDiagnostics || name === "skipLibCheck" || name === "skipDefaultLibCheck") {
856+
(result ||= {})[name] = convertToReusableCompilerOptionValue(
857+
optionInfo,
858+
options[name] as CompilerOptionsValue,
859+
relativeToBuildInfo
860+
);
861+
}
840862
}
841863
return result;
842864
}
@@ -1211,17 +1233,25 @@ namespace ts {
12111233
}
12121234
}
12131235

1236+
export function toBuilderStateFileInfo(fileInfo: ProgramBuildInfoFileInfo): BuilderState.FileInfo {
1237+
return isString(fileInfo) ?
1238+
{ version: fileInfo, signature: fileInfo, affectsGlobalScope: undefined } :
1239+
isString(fileInfo.signature) ?
1240+
fileInfo as BuilderState.FileInfo :
1241+
{ version: fileInfo.version, signature: fileInfo.signature === false ? undefined : fileInfo.version, affectsGlobalScope: fileInfo.affectsGlobalScope };
1242+
}
1243+
12141244
export function createBuildProgramUsingProgramBuildInfo(program: ProgramBuildInfo, buildInfoPath: string, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram {
12151245
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
12161246
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
12171247

12181248
const filePaths = program.fileNames.map(toPath);
12191249
const filePathsSetList = program.fileIdsList?.map(fileIds => new Set(fileIds.map(toFilePath)));
12201250
const fileInfos = new Map<Path, BuilderState.FileInfo>();
1221-
program.fileInfos.forEach((fileInfo, index) => fileInfos.set(toFilePath(index + 1), fileInfo));
1251+
program.fileInfos.forEach((fileInfo, index) => fileInfos.set(toFilePath(index + 1), toBuilderStateFileInfo(fileInfo)));
12221252
const state: ReusableBuilderProgramState = {
12231253
fileInfos,
1224-
compilerOptions: convertToOptionsWithAbsolutePaths(program.options, toAbsolutePath),
1254+
compilerOptions: program.options ? convertToOptionsWithAbsolutePaths(program.options, toAbsolutePath) : {},
12251255
referencedMap: toMapOfReferencedSet(program.referencedMap),
12261256
exportedModulesMap: toMapOfReferencedSet(program.exportedModulesMap),
12271257
semanticDiagnosticsPerFile: program.semanticDiagnosticsPerFile && arrayToMap(program.semanticDiagnosticsPerFile, value => toFilePath(isNumber(value) ? value : value[0]), value => isNumber(value) ? emptyArray : value[1]),

src/compiler/builderState.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace ts {
7474
export interface FileInfo {
7575
readonly version: string;
7676
signature: string | undefined;
77-
affectsGlobalScope: boolean;
77+
affectsGlobalScope: boolean | undefined;
7878
}
7979
/**
8080
* Referenced files with values for the keys as referenced file's path to be true
@@ -235,7 +235,7 @@ namespace ts {
235235
}
236236
}
237237
}
238-
fileInfos.set(sourceFile.resolvedPath, { version, signature: oldInfo && oldInfo.signature, affectsGlobalScope: isFileAffectingGlobalScope(sourceFile) });
238+
fileInfos.set(sourceFile.resolvedPath, { version, signature: oldInfo && oldInfo.signature, affectsGlobalScope: isFileAffectingGlobalScope(sourceFile) || undefined });
239239
}
240240

241241
return {

src/testRunner/unittests/tsbuild/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ interface Symbol {
242242
fileNames: readonly string[];
243243
fileNamesList: readonly (readonly string[])[] | undefined;
244244
fileInfos: MapLike<BuilderState.FileInfo>;
245-
options: CompilerOptions;
245+
options: CompilerOptions | undefined;
246246
referencedMap?: MapLike<string[]>;
247247
exportedModulesMap?: MapLike<string[]>;
248248
semanticDiagnosticsPerFile?: readonly ProgramBuildInfoDiagnostic[];
@@ -251,7 +251,7 @@ interface Symbol {
251251
type ReadableBuildInfo = Omit<BuildInfo, "program"> & { program: ProgramBuildInfo | undefined; size: number; };
252252
function generateBuildInfoProgramBaseline(sys: System, originalWriteFile: System["writeFile"], buildInfoPath: string, buildInfo: BuildInfo) {
253253
const fileInfos: ProgramBuildInfo["fileInfos"] = {};
254-
buildInfo.program?.fileInfos.forEach((fileInfo, index) => fileInfos[toFileName(index + 1)] = fileInfo);
254+
buildInfo.program?.fileInfos.forEach((fileInfo, index) => fileInfos[toFileName(index + 1)] = toBuilderStateFileInfo(fileInfo));
255255
const fileNamesList = buildInfo.program?.fileIdsList?.map(fileIdsListId => fileIdsListId.map(toFileName));
256256
const program: ProgramBuildInfo | undefined = buildInfo.program && {
257257
fileNames: buildInfo.program.fileNames,

src/testRunner/unittests/tscWatch/incremental.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ namespace ts.tscWatch {
167167
assert.deepEqual(state.fileInfos.get(file1.path as Path), {
168168
version: system.createHash(file1.content),
169169
signature: system.createHash(file1.content),
170-
affectsGlobalScope: false,
170+
affectsGlobalScope: undefined,
171171
});
172172
assert.deepEqual(state.fileInfos.get(file2.path as Path), {
173173
version: system.createHash(fileModified.content),
174174
signature: system.createHash(fileModified.content),
175-
affectsGlobalScope: false,
175+
affectsGlobalScope: undefined,
176176
});
177177

178178
assert.deepEqual(state.compilerOptions, {

tests/baselines/reference/tsbuild/configFileErrors/incremental-declaration-changes/builds-after-fixing-config-file-errors.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exports.bar = bar;
3434

3535

3636
//// [/src/tsconfig.tsbuildinfo]
37-
{"program":{"fileNames":["../lib/lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","signature":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"4646078106-export function foo() { }","signature":"4646078106-export function foo() { }","affectsGlobalScope":false},{"version":"1045484683-export function bar() { }","signature":"1045484683-export function bar() { }","affectsGlobalScope":false}],"options":{"composite":true,"configFilePath":"./tsconfig.json","declaration":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}
37+
{"program":{"fileNames":["../lib/lib.d.ts","./a.ts","./b.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},"4646078106-export function foo() { }","1045484683-export function bar() { }"],"options":{"composite":true,"declaration":true},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}
3838

3939
//// [/src/tsconfig.tsbuildinfo.readable.baseline.txt]
4040
{
@@ -52,18 +52,15 @@ exports.bar = bar;
5252
},
5353
"./a.ts": {
5454
"version": "4646078106-export function foo() { }",
55-
"signature": "4646078106-export function foo() { }",
56-
"affectsGlobalScope": false
55+
"signature": "4646078106-export function foo() { }"
5756
},
5857
"./b.ts": {
5958
"version": "1045484683-export function bar() { }",
60-
"signature": "1045484683-export function bar() { }",
61-
"affectsGlobalScope": false
59+
"signature": "1045484683-export function bar() { }"
6260
}
6361
},
6462
"options": {
6563
"composite": true,
66-
"configFilePath": "./tsconfig.json",
6764
"declaration": true
6865
},
6966
"referencedMap": {},
@@ -75,6 +72,6 @@ exports.bar = bar;
7572
]
7673
},
7774
"version": "FakeTSVersion",
78-
"size": 1456
75+
"size": 788
7976
}
8077

tests/baselines/reference/tsbuild/configFileExtends/initial-build/when-building-project-uses-reference-and-both-extend-config-with-include.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ exports.a = 1;
7272

7373

7474
//// [/src/target-tsc-build/shared/tsconfig.tsbuildinfo]
75-
{"program":{"fileNames":["../../../lib/lib.d.ts","../../shared/index.ts","../../shared/typings-base/globals.d.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","signature":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-22125360210-export const a: Unrestricted = 1;","signature":"-22125360210-export const a: Unrestricted = 1;","affectsGlobalScope":false},{"version":"4725476611-type Unrestricted = any;","signature":"4725476611-type Unrestricted = any;","affectsGlobalScope":true}],"options":{"composite":true,"configFilePath":"../../shared/tsconfig.json","listFiles":true,"outDir":"..","rootDir":"../.."},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}
75+
{"program":{"fileNames":["../../../lib/lib.d.ts","../../shared/index.ts","../../shared/typings-base/globals.d.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},"-22125360210-export const a: Unrestricted = 1;",{"version":"4725476611-type Unrestricted = any;","affectsGlobalScope":true}],"options":{"composite":true,"outDir":"..","rootDir":"../.."},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3]},"version":"FakeTSVersion"}
7676

7777
//// [/src/target-tsc-build/shared/tsconfig.tsbuildinfo.readable.baseline.txt]
7878
{
@@ -90,8 +90,7 @@ exports.a = 1;
9090
},
9191
"../../shared/index.ts": {
9292
"version": "-22125360210-export const a: Unrestricted = 1;",
93-
"signature": "-22125360210-export const a: Unrestricted = 1;",
94-
"affectsGlobalScope": false
93+
"signature": "-22125360210-export const a: Unrestricted = 1;"
9594
},
9695
"../../shared/typings-base/globals.d.ts": {
9796
"version": "4725476611-type Unrestricted = any;",
@@ -101,8 +100,6 @@ exports.a = 1;
101100
},
102101
"options": {
103102
"composite": true,
104-
"configFilePath": "../../shared/tsconfig.json",
105-
"listFiles": true,
106103
"outDir": "..",
107104
"rootDir": "../.."
108105
},
@@ -115,7 +112,7 @@ exports.a = 1;
115112
]
116113
},
117114
"version": "FakeTSVersion",
118-
"size": 1567
115+
"size": 901
119116
}
120117

121118
//// [/src/target-tsc-build/webpack/index.d.ts]
@@ -130,7 +127,7 @@ exports.b = 1;
130127

131128

132129
//// [/src/target-tsc-build/webpack/tsconfig.tsbuildinfo]
133-
{"program":{"fileNames":["../../../lib/lib.d.ts","../../webpack/index.ts","../../shared/typings-base/globals.d.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","signature":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-14405273073-export const b: Unrestricted = 1;","signature":"-14405273073-export const b: Unrestricted = 1;","affectsGlobalScope":false},{"version":"4725476611-type Unrestricted = any;","signature":"4725476611-type Unrestricted = any;","affectsGlobalScope":true}],"options":{"composite":true,"configFilePath":"../../webpack/tsconfig.json","listFiles":true,"outDir":"..","rootDir":"../.."},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,3,2]},"version":"FakeTSVersion"}
130+
{"program":{"fileNames":["../../../lib/lib.d.ts","../../webpack/index.ts","../../shared/typings-base/globals.d.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},"-14405273073-export const b: Unrestricted = 1;",{"version":"4725476611-type Unrestricted = any;","affectsGlobalScope":true}],"options":{"composite":true,"outDir":"..","rootDir":"../.."},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,3,2]},"version":"FakeTSVersion"}
134131

135132
//// [/src/target-tsc-build/webpack/tsconfig.tsbuildinfo.readable.baseline.txt]
136133
{
@@ -148,8 +145,7 @@ exports.b = 1;
148145
},
149146
"../../webpack/index.ts": {
150147
"version": "-14405273073-export const b: Unrestricted = 1;",
151-
"signature": "-14405273073-export const b: Unrestricted = 1;",
152-
"affectsGlobalScope": false
148+
"signature": "-14405273073-export const b: Unrestricted = 1;"
153149
},
154150
"../../shared/typings-base/globals.d.ts": {
155151
"version": "4725476611-type Unrestricted = any;",
@@ -159,8 +155,6 @@ exports.b = 1;
159155
},
160156
"options": {
161157
"composite": true,
162-
"configFilePath": "../../webpack/tsconfig.json",
163-
"listFiles": true,
164158
"outDir": "..",
165159
"rootDir": "../.."
166160
},
@@ -173,6 +167,6 @@ exports.b = 1;
173167
]
174168
},
175169
"version": "FakeTSVersion",
176-
"size": 1569
170+
"size": 902
177171
}
178172

0 commit comments

Comments
 (0)