Skip to content

Commit d8b61df

Browse files
committed
Revert "remove perfTracker tracking..."
This reverts commit cf10a91.
1 parent cf10a91 commit d8b61df

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { CompilerInterface } from './PrepareCompiler';
2323
import { YamlCompiler } from './YamlCompiler';
2424
import { CubeDictionary } from './CubeDictionary';
2525
import { CompilerCache } from './CompilerCache';
26+
import { perfTracker } from './PerfTracker';
2627

2728
const ctxFileStorage = new AsyncLocalStorage<FileContent>();
2829

@@ -211,8 +212,12 @@ export class DataSchemaCompiler {
211212
}
212213

213214
protected async doCompile() {
215+
const compileTimer = perfTracker.start('doCompile', true);
216+
214217
const files = await this.repository.dataSchemaFiles();
215218

219+
console.log(`Compiling ${files.length} files...`);
220+
216221
this.pythonContext = await this.loadPythonContext(files, 'globals.py');
217222
this.yamlCompiler.initFromPythonContext(this.pythonContext);
218223

@@ -235,6 +240,8 @@ export class DataSchemaCompiler {
235240
}
236241

237242
const transpile = async (stage: CompileStage): Promise<FileContent[]> => {
243+
const transpileTimer = perfTracker.start(`transpilation-stage-${stage}`);
244+
238245
let cubeNames: string[] = [];
239246
let cubeSymbols: Record<string, Record<string, boolean>> = {};
240247
let transpilerNames: string[] = [];
@@ -301,6 +308,8 @@ export class DataSchemaCompiler {
301308
results = await Promise.all(toCompile.map(f => this.transpileFile(f, errorsReport, {})));
302309
}
303310

311+
transpileTimer.end();
312+
304313
return results.filter(f => !!f) as FileContent[];
305314
};
306315

@@ -398,6 +407,8 @@ export class DataSchemaCompiler {
398407
});
399408

400409
const compilePhase = async (compilers: CompileCubeFilesCompilers, stage: 0 | 1 | 2 | 3) => {
410+
const compilePhaseTimer = perfTracker.start(`compilation-phase-${stage}`);
411+
401412
// clear the objects for the next phase
402413
cubes = [];
403414
exports = {};
@@ -406,7 +417,9 @@ export class DataSchemaCompiler {
406417
asyncModules = [];
407418
transpiledFiles = await transpile(stage);
408419

409-
return this.compileCubeFiles(cubes, contexts, compiledFiles, asyncModules, compilers, transpiledFiles, errorsReport);
420+
const res = this.compileCubeFiles(cubes, contexts, compiledFiles, asyncModules, compilers, transpiledFiles, errorsReport);
421+
compilePhaseTimer.end();
422+
return res;
410423
};
411424

412425
return compilePhase({ cubeCompilers: this.cubeNameCompilers }, 0)
@@ -442,6 +455,12 @@ export class DataSchemaCompiler {
442455
} else if (transpilationWorkerThreads && this.workerPool) {
443456
this.workerPool.terminate();
444457
}
458+
459+
// End overall compilation timing and print performance report
460+
compileTimer.end();
461+
setImmediate(() => {
462+
perfTracker.printReport();
463+
});
445464
});
446465
}
447466

@@ -640,7 +659,9 @@ export class DataSchemaCompiler {
640659
asyncModules
641660
);
642661
});
662+
const asyncModulesTimer = perfTracker.start('asyncModules.reduce (jinja)');
643663
await asyncModules.reduce((a: Promise<void>, b: CallableFunction) => a.then(() => b()), Promise.resolve());
664+
asyncModulesTimer.end();
644665
return this.compileObjects(compilers.cubeCompilers || [], cubes, errorsReport)
645666
.then(() => this.compileObjects(compilers.contextCompilers || [], contexts, errorsReport));
646667
}
@@ -663,7 +684,9 @@ export class DataSchemaCompiler {
663684
compiledFiles[file.fileName] = true;
664685

665686
if (file.fileName.endsWith('.js')) {
687+
const compileJsFileTimer = perfTracker.start('compileJsFile');
666688
this.compileJsFile(file, errorsReport, { doSyntaxCheck });
689+
compileJsFileTimer.end();
667690
} else if (file.fileName.endsWith('.yml.jinja') || file.fileName.endsWith('.yaml.jinja') ||
668691
(
669692
file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml')
@@ -677,7 +700,9 @@ export class DataSchemaCompiler {
677700
this.pythonContext!
678701
));
679702
} else if (file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml')) {
703+
const compileYamlFileTimer = perfTracker.start('compileYamlFile');
680704
this.yamlCompiler.compileYamlFile(file, errorsReport);
705+
compileYamlFileTimer.end();
681706
}
682707
}
683708

packages/cubejs-schema-compiler/src/compiler/YamlCompiler.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { nonStringFields } from './CubeValidator';
1616
import { CubeDictionary } from './CubeDictionary';
1717
import { ErrorReporter } from './ErrorReporter';
1818
import { camelizeCube } from './utils';
19+
import { perfTracker } from './PerfTracker';
1920

2021
type EscapeStateStack = {
2122
inFormattedStr?: boolean;
@@ -92,7 +93,9 @@ export class YamlCompiler {
9293
for (const key of Object.keys(yamlObj)) {
9394
if (key === 'cubes') {
9495
(yamlObj.cubes || []).forEach(({ name, ...cube }) => {
96+
const transpileAndPrepareJsFileTimer = perfTracker.start('yaml-transpileAndPrepareJsFile');
9597
const transpiledFile = this.transpileAndPrepareJsFile(file, 'cube', { name, ...cube }, errorsReport);
98+
transpileAndPrepareJsFileTimer.end();
9699
this.dataSchemaCompiler?.compileJsFile(transpiledFile, errorsReport);
97100
});
98101
} else if (key === 'views') {
@@ -134,7 +137,10 @@ export class YamlCompiler {
134137

135138
cubeObj.hierarchies = this.yamlArrayToObj(cubeObj.hierarchies || [], 'hierarchies', errorsReport);
136139

137-
return this.transpileYaml(cubeObj, [], cubeObj.name, errorsReport);
140+
const transpileYamlTimer = perfTracker.start('transpileYaml');
141+
const res = this.transpileYaml(cubeObj, [], cubeObj.name, errorsReport);
142+
transpileYamlTimer.end();
143+
return res;
138144
}
139145

140146
private transpileYaml(obj, propertyPath, cubeName, errorsReport: ErrorReporter) {
@@ -163,7 +169,9 @@ export class YamlCompiler {
163169
if (propertyPath[propertyPath.length - 1] === 'values') {
164170
if (typeof code === 'string') {
165171
if (code.match(PY_TEMPLATE_SYNTAX)) {
172+
const parsePythonAndTranspileToJsTimer184 = perfTracker.start('parsePythonAndTranspileToJs call 184');
166173
ast = this.parsePythonAndTranspileToJs(`f"${this.escapeDoubleQuotes(code)}"`, errorsReport);
174+
parsePythonAndTranspileToJsTimer184.end();
167175
} else {
168176
ast = t.stringLiteral(code);
169177
}
@@ -178,7 +186,9 @@ export class YamlCompiler {
178186
}
179187
}
180188
if (ast === null) {
189+
const parsePythonAndTranspileToJsTimer201 = perfTracker.start('parsePythonAndTranspileToJs call 201');
181190
ast = this.parsePythonAndTranspileToJs(code, errorsReport);
191+
parsePythonAndTranspileToJsTimer201.end();
182192
}
183193
return this.extractProgramBodyIfNeeded(ast);
184194
}).filter(ast => !!ast)))]);
@@ -189,7 +199,9 @@ export class YamlCompiler {
189199
}
190200

191201
if (propertyPath[propertyPath.length - 1] === 'extends') {
202+
const parsePythonAndTranspileToJsTimer214 = perfTracker.start('parsePythonAndTranspileToJs call 214');
192203
const ast = this.parsePythonAndTranspileToJs(obj, errorsReport);
204+
parsePythonAndTranspileToJsTimer214.end();
193205
return this.astIntoArrowFunction(ast, obj, cubeName, name => this.cubeDictionary.resolveCube(name));
194206
} else if (typeof obj === 'string') {
195207
let code = obj;
@@ -203,7 +215,9 @@ export class YamlCompiler {
203215
code = `f"${this.escapeDoubleQuotes(obj)}"`;
204216
}
205217

218+
const parsePythonAndTranspileToJsTimer225 = perfTracker.start('parsePythonAndTranspileToJs call 225');
206219
const ast = this.parsePythonAndTranspileToJs(code, errorsReport);
220+
parsePythonAndTranspileToJsTimer225.end();
207221
return this.extractProgramBodyIfNeeded(ast);
208222
}
209223

@@ -288,7 +302,9 @@ export class YamlCompiler {
288302
}
289303

290304
private parsePythonIntoArrowFunction(codeString: string, cubeName, originalObj, errorsReport: ErrorReporter) {
305+
const parsePythonAndTranspileToJsTimer301 = perfTracker.start('parsePythonAndTranspileToJs call 301');
291306
const ast = this.parsePythonAndTranspileToJs(codeString, errorsReport);
307+
parsePythonAndTranspileToJsTimer301.end();
292308
return this.astIntoArrowFunction(ast as any, codeString, cubeName);
293309
}
294310

@@ -298,8 +314,12 @@ export class YamlCompiler {
298314
}
299315

300316
try {
317+
const parsePythonAndTranspileToJsTimer = perfTracker.start('PythonParser->transpileToJs()');
318+
301319
const pythonParser = new PythonParser(codeString);
302-
return pythonParser.transpileToJs();
320+
const res = pythonParser.transpileToJs();
321+
parsePythonAndTranspileToJsTimer.end();
322+
return res;
303323
} catch (e: any) {
304324
errorsReport.error(`Can't parse python expression. Most likely this type of syntax isn't supported yet: ${e.message || e}`);
305325
}
@@ -308,6 +328,7 @@ export class YamlCompiler {
308328
}
309329

310330
private astIntoArrowFunction(input: t.Program | t.NullLiteral, codeString: string, cubeName, resolveSymbol?: (string) => any) {
331+
const astIntoArrowFunctionTimer = perfTracker.start('astIntoArrowFunction');
311332
const initialJs = babelGenerator(input, {}, codeString).code;
312333

313334
// Re-parse generated JS to set all necessary parent paths
@@ -332,6 +353,7 @@ export class YamlCompiler {
332353
babelTraverse(ast, traverseObj);
333354

334355
const body: any = ast.program.body[0];
356+
astIntoArrowFunctionTimer.end();
335357
return body?.expression;
336358
}
337359

0 commit comments

Comments
 (0)