Skip to content

Commit c7bf7d7

Browse files
ovrKSDaemon
andauthored
refactor(schema-compiler): Drop support for disabling native workers … (#10196)
This flag is enabled by default for a long time and there are not side effect. I am working on speeding up Cube startup and I've figure out that we load babel, which we don't need in the Cube Cloud Runtime, because it uses native transpilers. So, let's remove this env variable and speedup cloud as side effect. --------- Co-authored-by: Konstantin Burkalev <[email protected]>
1 parent 499ddc6 commit c7bf7d7

File tree

13 files changed

+31
-78
lines changed

13 files changed

+31
-78
lines changed

.github/workflows/drivers-tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ jobs:
369369
(contains(env.CLOUD_DATABASES, matrix.database) && env.DRIVERS_TESTS_ATHENA_CUBEJS_AWS_KEY != '') ||
370370
(!contains(env.CLOUD_DATABASES, matrix.database))
371371
env:
372-
DRIVERS_TESTS_CUBEJS_TRANSPILATION_WORKER_THREADS: true
373372
DRIVERS_TESTS_CUBEJS_TRANSPILATION_NATIVE: false
374373
DRIVERS_TESTS_CUBEJS_TESSERACT_SQL_PLANNER: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.use_tesseract_sql_planner) || matrix.use_tesseract_sql_planner }}
375374

docs/pages/product/configuration/reference/environment-variables.mdx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,21 +1467,6 @@ learn more.
14671467
| --------------- | ---------------------- | --------------------- |
14681468
| A valid number | 86400 | 86400 |
14691469

1470-
## `CUBEJS_TRANSPILATION_WORKER_THREADS`
1471-
1472-
If `true`, optimizes data model compilation by running critical parts of the
1473-
code in worker threads.
1474-
1475-
| Possible Values | Default in Development | Default in Production |
1476-
| --------------- | ---------------------- | --------------------- |
1477-
| `true`, `false` | `true` | `true` |
1478-
1479-
<ReferenceBox>
1480-
1481-
See [this issue](https://github.com/cube-js/cube/issues/9285) for details.
1482-
1483-
</ReferenceBox>
1484-
14851470
## `CUBEJS_WEB_SOCKETS`
14861471

14871472
If `true`, then use WebSocket for data fetching.
@@ -1911,4 +1896,4 @@ The port for a Cube deployment to listen to API connections on.
19111896
[ref-mdx-api-locale]: /product/apis-integrations/mdx-api#measure-format
19121897
[ref-time-dimensions]: /product/data-modeling/reference/dimensions#time
19131898
[ref-time-zone]: /product/apis-integrations/queries#time-zone
1914-
[link-tzdb]: https://en.wikipedia.org/wiki/Tz_database
1899+
[link-tzdb]: https://en.wikipedia.org/wiki/Tz_database

packages/cubejs-backend-shared/src/env.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,19 @@ const variables: Record<string, (...args: any) => any> = {
228228
nativeOrchestrator: () => get('CUBEJS_TESSERACT_ORCHESTRATOR')
229229
.default('true')
230230
.asBoolStrict(),
231-
transpilationWorkerThreads: () => get('CUBEJS_TRANSPILATION_WORKER_THREADS')
232-
.default('true')
233-
.asBoolStrict(),
231+
transpilationWorkerThreads: () => {
232+
const enabled = get('CUBEJS_TRANSPILATION_WORKER_THREADS')
233+
.default('true')
234+
.asBoolStrict();
235+
236+
if (!enabled) {
237+
console.warn(
238+
'Worker thread transpilation is enabled by default and cannot be disabled with CUBEJS_TRANSPILATION_WORKER_THREADS.'
239+
);
240+
}
241+
242+
return true;
243+
},
234244
allowNonStrictDateRangeMatching: () => get('CUBEJS_PRE_AGGREGATIONS_ALLOW_NON_STRICT_DATE_RANGE_MATCH')
235245
.default('true')
236246
.asBoolStrict(),
@@ -2186,6 +2196,9 @@ export function getEnv<T extends keyof Vars>(key: T, opts?: Parameters<Vars[T]>)
21862196
);
21872197
}
21882198

2199+
// trigger warning
2200+
getEnv('transpilationWorkerThreads');
2201+
21892202
export function isDockerImage(): boolean {
21902203
return Boolean(process.env.CUBEJS_DOCKER_IMAGE_TAG);
21912204
}

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

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import fs from 'fs';
55
import os from 'os';
66
import path from 'path';
77
import syntaxCheck from 'syntax-error';
8-
import { parse } from '@babel/parser';
9-
import babelGenerator from '@babel/generator';
10-
import babelTraverse from '@babel/traverse';
118
import R from 'ramda';
129
import workerpool from 'workerpool';
1310
import { LRUCache } from 'lru-cache';
@@ -275,12 +272,11 @@ export class DataSchemaCompiler {
275272
const errorsReport = new ErrorReporter(null, [], this.errorReportOptions);
276273
this.errorsReporter = errorsReport;
277274

278-
const transpilationWorkerThreads = getEnv('transpilationWorkerThreads');
279275
const transpilationNative = getEnv('transpilationNative');
280276
const transpilationNativeThreadsCount = getThreadsCount();
281277
const { compilerId } = this;
282278

283-
if (transpilationWorkerThreads) {
279+
if (!transpilationNative) {
284280
const wc = getEnv('transpilationWorkerThreadsCount');
285281
this.workerPool = workerpool.pool(
286282
path.join(__dirname, 'transpilers/transpiler_worker'),
@@ -292,11 +288,10 @@ export class DataSchemaCompiler {
292288
let cubeNames: string[] = [];
293289
let cubeSymbols: Record<string, Record<string, boolean>> = {};
294290
let transpilerNames: string[] = [];
295-
let results: (FileContent | undefined)[];
296291

297-
if (transpilationNative || transpilationWorkerThreads) {
298-
({ cubeNames, cubeSymbols, transpilerNames } = this.prepareTranspileSymbols());
299-
}
292+
({ cubeNames, cubeSymbols, transpilerNames } = this.prepareTranspileSymbols());
293+
294+
let results: (FileContent | undefined)[];
300295

301296
if (transpilationNative) {
302297
const jsFiles = originalJsFiles;
@@ -325,28 +320,25 @@ export class DataSchemaCompiler {
325320
.map(f => this.transpileJinjaFile(f, errorsReport, { cubeNames, cubeSymbols, transpilerNames }));
326321

327322
results = (await Promise.all([...jsFilesTasks, ...yamlFilesTasks, ...jinjaFilesTasks])).flat();
328-
} else if (transpilationWorkerThreads) {
329-
results = await Promise.all(toCompile.map(f => this.transpileFile(f, errorsReport, { cubeNames, cubeSymbols, transpilerNames })));
330323
} else {
331-
results = await Promise.all(toCompile.map(f => this.transpileFile(f, errorsReport, {})));
324+
results = await Promise.all(toCompile.map(f => this.transpileFile(f, errorsReport, { cubeNames, cubeSymbols, transpilerNames })));
332325
}
333326

334327
return results.filter(f => !!f) as FileContent[];
335328
};
336329

337330
const transpilePhase = async (stage: CompileStage): Promise<FileContent[]> => {
338-
let cubeNames: string[] = [];
339-
let cubeSymbols: Record<string, Record<string, boolean>> = {};
340-
let transpilerNames: string[] = [];
341331
let results: (FileContent | undefined)[];
342332

343333
if (toCompile.length === 0) {
344334
return [];
345335
}
346336

347-
if (transpilationNative || transpilationWorkerThreads) {
348-
({ cubeNames, cubeSymbols, transpilerNames } = this.prepareTranspileSymbols());
349-
}
337+
let cubeNames: string[] = [];
338+
let cubeSymbols: Record<string, Record<string, boolean>> = {};
339+
let transpilerNames: string[] = [];
340+
341+
({ cubeNames, cubeSymbols, transpilerNames } = this.prepareTranspileSymbols());
350342

351343
// After the first phase all files are with JS source code: original or transpiled
352344

@@ -363,10 +355,8 @@ export class DataSchemaCompiler {
363355
const jsFilesTasks = jsChunks.map(chunk => this.transpileJsFilesNativeBulk(chunk, errorsReport, { transpilerNames, compilerId }));
364356

365357
results = (await Promise.all(jsFilesTasks)).flat();
366-
} else if (transpilationWorkerThreads) {
367-
results = await Promise.all(toCompile.map(f => this.transpileJsFile(f, errorsReport, { cubeNames, cubeSymbols, transpilerNames })));
368358
} else {
369-
results = await Promise.all(toCompile.map(f => this.transpileJsFile(f, errorsReport, {})));
359+
results = await Promise.all(toCompile.map(f => this.transpileJsFile(f, errorsReport, { cubeNames, cubeSymbols, transpilerNames })));
370360
}
371361

372362
return results.filter(f => !!f) as FileContent[];
@@ -520,7 +510,7 @@ export class DataSchemaCompiler {
520510
errorsReport,
521511
{ cubeNames: [], cubeSymbols: {}, transpilerNames: [], contextSymbols: {}, compilerId: this.compilerId, stage: 0 }
522512
).then(() => undefined);
523-
} else if (transpilationWorkerThreads && this.workerPool) {
513+
} else if (this.workerPool) {
524514
this.workerPool.terminate();
525515
}
526516
});
@@ -701,7 +691,7 @@ export class DataSchemaCompiler {
701691
errorsReport.exitFile();
702692

703693
return { ...file, content: res[0].code };
704-
} else if (getEnv('transpilationWorkerThreads')) {
694+
} else {
705695
const data = {
706696
fileName: file.fileName,
707697
content: file.content,
@@ -715,25 +705,6 @@ export class DataSchemaCompiler {
715705
errorsReport.addWarnings(res.warnings);
716706

717707
return { ...file, content: res.content };
718-
} else {
719-
const ast = parse(
720-
file.content,
721-
{
722-
sourceFilename: file.fileName,
723-
sourceType: 'module',
724-
plugins: ['objectRestSpread'],
725-
},
726-
);
727-
728-
errorsReport.inFile(file);
729-
this.transpilers.forEach((t) => {
730-
babelTraverse(ast, t.traverseObject(errorsReport));
731-
});
732-
errorsReport.exitFile();
733-
734-
const content = babelGenerator(ast, {}, file.content).code;
735-
736-
return { ...file, content };
737708
}
738709
} catch (e: any) {
739710
if (e.toString().indexOf('SyntaxError') !== -1) {
@@ -778,7 +749,7 @@ export class DataSchemaCompiler {
778749
this.compiledYamlCache.set(cacheKey, res[0].code);
779750

780751
return { ...file, content: res[0].code };
781-
} else if (getEnv('transpilationWorkerThreads')) {
752+
} else {
782753
const data = {
783754
fileName: file.fileName,
784755
content: file.content,
@@ -794,12 +765,6 @@ export class DataSchemaCompiler {
794765
this.compiledYamlCache.set(cacheKey, res.content);
795766

796767
return { ...file, content: res.content };
797-
} else {
798-
const transpiledFile = this.yamlCompiler.transpileYamlFile(file, errorsReport);
799-
800-
this.compiledYamlCache.set(cacheKey, transpiledFile?.content || '');
801-
802-
return transpiledFile;
803768
}
804769
}
805770

packages/cubejs-testing-drivers/fixtures/athena.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"CUBEJS_SQL_PASSWORD": "admin_password",
1818
"CUBESQL_SQL_PUSH_DOWN": "true",
1919
"CUBEJS_TESSERACT_SQL_PLANNER": "${DRIVERS_TESTS_CUBEJS_TESSERACT_SQL_PLANNER}",
20-
"CUBEJS_TRANSPILATION_WORKER_THREADS": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_WORKER_THREADS}",
2120
"CUBEJS_TRANSPILATION_NATIVE": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_NATIVE}"
2221
},
2322
"ports" : ["4000", "5656"]

packages/cubejs-testing-drivers/fixtures/bigquery.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"CUBEJS_DB_EXPORT_BUCKET": "cube-open-source-export-bucket",
2020
"CUBEJS_DB_EXPORT_BUCKET_TYPE": "gcp",
2121
"CUBEJS_TESSERACT_SQL_PLANNER": "${DRIVERS_TESTS_CUBEJS_TESSERACT_SQL_PLANNER}",
22-
"CUBEJS_TRANSPILATION_WORKER_THREADS": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_WORKER_THREADS}",
2322
"CUBEJS_TRANSPILATION_NATIVE": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_NATIVE}"
2423
},
2524
"ports" : ["4000", "5656"]

packages/cubejs-testing-drivers/fixtures/clickhouse.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"CUBEJS_SQL_PASSWORD": "admin_password",
3939
"CUBESQL_SQL_PUSH_DOWN": "true",
4040
"CUBEJS_TESSERACT_SQL_PLANNER": "${DRIVERS_TESTS_CUBEJS_TESSERACT_SQL_PLANNER}",
41-
"CUBEJS_TRANSPILATION_WORKER_THREADS": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_WORKER_THREADS}",
4241
"CUBEJS_TRANSPILATION_NATIVE": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_NATIVE}"
4342
},
4443
"depends_on": ["data"],

packages/cubejs-testing-drivers/fixtures/databricks-jdbc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
"CUBEJS_SQL_PASSWORD": "admin_password",
8080
"CUBESQL_SQL_PUSH_DOWN": "true",
8181
"CUBEJS_TESSERACT_SQL_PLANNER": "${DRIVERS_TESTS_CUBEJS_TESSERACT_SQL_PLANNER}",
82-
"CUBEJS_TRANSPILATION_WORKER_THREADS": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_WORKER_THREADS}",
8382
"CUBEJS_TRANSPILATION_NATIVE": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_NATIVE}"
8483
},
8584
"ports" : ["4000", "5656"]

packages/cubejs-testing-drivers/fixtures/mssql.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"CUBEJS_SQL_PASSWORD": "admin_password",
1414
"CUBESQL_SQL_PUSH_DOWN": "true",
1515
"CUBEJS_TESSERACT_SQL_PLANNER": "${DRIVERS_TESTS_CUBEJS_TESSERACT_SQL_PLANNER}",
16-
"CUBEJS_TRANSPILATION_WORKER_THREADS": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_WORKER_THREADS}",
1716
"CUBEJS_TRANSPILATION_NATIVE": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_NATIVE}"
1817
},
1918
"depends_on": ["data"],

packages/cubejs-testing-drivers/fixtures/mysql.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"CUBEJS_SQL_PASSWORD": "admin_password",
1515
"CUBESQL_SQL_PUSH_DOWN": "true",
1616
"CUBEJS_TESSERACT_SQL_PLANNER": "${DRIVERS_TESTS_CUBEJS_TESSERACT_SQL_PLANNER}",
17-
"CUBEJS_TRANSPILATION_WORKER_THREADS": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_WORKER_THREADS}",
1817
"CUBEJS_TRANSPILATION_NATIVE": "${DRIVERS_TESTS_CUBEJS_TRANSPILATION_NATIVE}"
1918
},
2019
"depends_on": ["data"],

0 commit comments

Comments
 (0)