Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e0ee7c1
add convertedToJs flag
KSDaemon Aug 27, 2025
2383fbf
pass toCompile to compileCubeFiles()
KSDaemon Aug 27, 2025
10b6c88
refactored compileYamlFile() to not call compileJsFile directly
KSDaemon Aug 27, 2025
1d9b917
moved yaml transpilation to transpile phase
KSDaemon Aug 27, 2025
15c10cb
removed dataSchemaCompiler from YamlCompiler's deps
KSDaemon Aug 27, 2025
1f5e856
renaming
KSDaemon Aug 27, 2025
02ad34b
simplified code
KSDaemon Aug 27, 2025
e5be4c1
add PerfTracker
KSDaemon Aug 28, 2025
c80d7a4
inject perTracker measures in dataschemacompiler
KSDaemon Aug 28, 2025
910f711
update CubePropContextTranspiler to support string keys
KSDaemon Aug 28, 2025
81a2a76
replace original content with js on first phase
KSDaemon Aug 28, 2025
70511f9
update arrow func expression instead of blind copying
KSDaemon Aug 28, 2025
467bd2b
fix grammar
KSDaemon Aug 28, 2025
ccf779e
more types
KSDaemon Aug 28, 2025
7e4736c
Preload Jinja templates to the engine
KSDaemon Aug 29, 2025
9c3e712
remove perf logging
KSDaemon Sep 5, 2025
7fb641f
simplified compileFile
KSDaemon Sep 8, 2025
27b8032
avoid mutating original repository files
KSDaemon Sep 9, 2025
164cda5
linter fix
KSDaemon Sep 9, 2025
37640f7
filter out files we don't transpile/compile
KSDaemon Sep 9, 2025
e585302
move PerfTracker to backend-shared
KSDaemon Sep 10, 2025
62167d6
Refactor doCompile() to avoid content mutation
KSDaemon Sep 11, 2025
36eb395
refactor: split first and later compile/transpile stages
KSDaemon Sep 11, 2025
ec718ab
improve transpilationNative
KSDaemon Sep 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions packages/cubejs-backend-shared/src/PerfTracker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { performance, PerformanceObserver } from 'perf_hooks';

interface PerfMetric {
count: number;
totalTime: number;
avgTime: number;
}

interface PerfStats {
[key: string]: PerfMetric;
}

class PerfTracker {
private metrics: PerfStats = {};

private globalMetric: string | null = null;

public constructor() {
const obs = new PerformanceObserver((items) => {
for (const entry of items.getEntries()) {
const { name } = entry;
if (!this.metrics[name]) {
this.metrics[name] = { count: 0, totalTime: 0, avgTime: 0 };
}
const m = this.metrics[name];
m.count++;
m.totalTime += entry.duration;
m.avgTime = m.totalTime / m.count;
}
});
obs.observe({ entryTypes: ['measure'] });
}

public start(name: string, global: boolean = false): { end: () => void } {
const uid = `${name}-${performance.now()}`;
const startMark = `${uid}-start`;
const endMark = `${uid}-end`;
performance.mark(startMark);

if (global && !this.globalMetric) {
this.globalMetric = name;
}

let ended = false;

return {
end: () => {
if (ended) return;
performance.mark(endMark);
performance.measure(name, startMark, endMark);
ended = true;
}
};
}

public printReport() {
console.log('\n🚀 PERFORMANCE REPORT 🚀\n');
console.log('═'.repeat(90));

const sorted = Object.entries(this.metrics)
.sort(([, a], [, b]) => b.totalTime - a.totalTime);

if (!sorted.length) {
console.log('No performance data collected.');
return;
}

let totalTime: number = 0;

if (this.globalMetric) {
totalTime = this.metrics[this.globalMetric]?.totalTime;
} else {
totalTime = sorted.reduce((sum, [, m]) => sum + m.totalTime, 0);
}

console.log(`⏱️ TOTAL TIME: ${totalTime.toFixed(2)}ms\n`);

sorted.forEach(([name, m]) => {
const pct = totalTime > 0 ? (m.totalTime / totalTime * 100) : 0;
console.log(` ${name.padEnd(40)} │ ${m.totalTime.toFixed(2).padStart(8)}ms │ ${m.avgTime.toFixed(2).padStart(7)}ms avg │ ${pct.toFixed(1).padStart(5)}% │ ${m.count.toString().padStart(4)} calls`);
});

console.log('═'.repeat(90));
console.log('🎯 End of Performance Report\n');
}
}

export const perfTracker = new PerfTracker();
1 change: 1 addition & 0 deletions packages/cubejs-backend-shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * from './process';
export * from './platform';
export * from './FileRepository';
export * from './decorators';
export * from './PerfTracker';
Loading
Loading