Skip to content

Commit 8a85aa5

Browse files
committed
perf: use advanced serialization
1 parent 6e8929e commit 8a85aa5

15 files changed

Lines changed: 59 additions & 101 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
matrix:
7777
# run ut in macOS, as SWC cases will fail in Ubuntu CI
7878
os: [macos-14, windows-latest]
79-
node_version: [18, 20, 22, 24]
79+
node_version: [20, 22, 24]
8080

8181
steps:
8282
- name: Checkout

packages/core/LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ Licensed under MIT license in the repository at https://github.com/rspack-contri
11591159

11601160
> MIT License
11611161
>
1162-
> Copyright (c) 2023-present ByteDance, Inc. and its affiliates.
1162+
> Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
11631163
>
11641164
> Permission is hereby granted, free of charge, to any person obtaining a copy
11651165
> of this software and associated documentation files (the "Software"), to deal

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"dependencies": {
5555
"@types/chai": "^5.2.3",
5656
"@rsbuild/core": "1.7.0-beta.0",
57-
"tinypool": "^1.1.1"
57+
"tinypool": "https://pkg.pr.new/tinypool@128"
5858
},
5959
"devDependencies": {
6060
"chai": "^5.3.3",

packages/core/src/core/listTests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
ListCommandResult,
77
Location,
88
RstestContext,
9-
Test,
9+
TestInfo,
1010
} from '../types';
1111
import {
1212
bgColor,
@@ -230,7 +230,7 @@ export async function listTests(
230230
type: 'file' | 'suite' | 'case';
231231
}[] = [];
232232

233-
const traverseTests = (test: Test) => {
233+
const traverseTests = (test: TestInfo) => {
234234
if (['skip', 'todo'].includes(test.runMode)) {
235235
return;
236236
}

packages/core/src/pool/forks.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import EventEmitter from 'node:events';
22
import { fileURLToPath } from 'node:url';
3-
import v8 from 'node:v8';
43
import { createBirpc } from 'birpc';
54
import { dirname, resolve } from 'pathe';
65
import { type Options, Tinypool } from 'tinypool';
@@ -31,8 +30,6 @@ function createChannel(rpcMethods: RuntimeRPC) {
3130
};
3231

3332
createBirpc<ServerRPC, RuntimeRPC>(rpcMethods, {
34-
serialize: v8.serialize,
35-
deserialize: (v) => v8.deserialize(Buffer.from(v)),
3633
post(v) {
3734
emitter.emit(events.message, v);
3835
},
@@ -78,6 +75,7 @@ export const createForksPool = (poolOptions: {
7875
minThreads,
7976
concurrentTasksPerWorker: 1,
8077
isolateWorkers: isolate,
78+
serialization: 'advanced',
8179
};
8280

8381
const pool = new Tinypool(options);

packages/core/src/pool/index.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@ import type {
88
RstestContext,
99
RuntimeConfig,
1010
RuntimeRPC,
11-
Test,
1211
TestCaseInfo,
1312
TestFileInfo,
1413
TestFileResult,
14+
TestInfo,
1515
TestResult,
1616
TestSuiteInfo,
1717
UserConsoleLog,
1818
} from '../types';
19-
import {
20-
color,
21-
needFlagExperimentalDetectModule,
22-
serializableConfig,
23-
} from '../utils';
19+
import { color, needFlagExperimentalDetectModule } from '../utils';
2420
import { isMemorySufficient } from '../utils/memory';
2521
import { createForksPool } from './forks';
2622

@@ -139,7 +135,7 @@ export const createPool = async ({
139135
project: ProjectContext;
140136
}) => Promise<
141137
{
142-
tests: Test[];
138+
tests: TestInfo[];
143139
testPath: string;
144140
errors?: FormattedError[];
145141
project: string;
@@ -295,7 +291,7 @@ export const createPool = async ({
295291
project: projectName,
296292
rootPath: context.rootPath,
297293
projectRoot: project.rootPath,
298-
runtimeConfig: serializableConfig(runtimeConfig),
294+
runtimeConfig,
299295
},
300296
type: 'run',
301297
setupEntries,
@@ -403,7 +399,7 @@ export const createPool = async ({
403399
outputModule: project.outputModule,
404400
rootPath: context.rootPath,
405401
projectRoot: project.rootPath,
406-
runtimeConfig: serializableConfig(runtimeConfig),
402+
runtimeConfig,
407403
},
408404
type: 'collect',
409405
setupEntries,

packages/core/src/runtime/api/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type {
22
Rstest,
33
RstestExpect,
44
RunnerHooks,
5-
Test,
65
TestCase,
76
TestFileResult,
7+
TestInfo,
88
WorkerState,
99
} from '../../types';
1010
import { createRunner } from '../runner';
@@ -20,7 +20,7 @@ export const createRstestRuntime = async (
2020
hooks: RunnerHooks,
2121
api: Rstest,
2222
) => Promise<TestFileResult>;
23-
collectTests: () => Promise<Test[]>;
23+
collectTests: () => Promise<TestInfo[]>;
2424
getCurrentTest: () => TestCase | undefined;
2525
};
2626
api: Rstest;

packages/core/src/runtime/runner/index.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
1919
hooks: RunnerHooks,
2020
api: Rstest,
2121
) => Promise<TestFileResult>;
22-
collectTests: () => Promise<Test[]>;
22+
collectTests: () => Promise<TestInfo[]>;
2323
getCurrentTest: TestRunner['getCurrentTest'];
2424
};
2525
} {
@@ -55,18 +55,7 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
5555
traverseUpdateTest(tests, testNamePattern);
5656
hooks.onTestFileReady?.({
5757
testPath,
58-
tests: tests.map(function toTestInfo(test: Test): TestInfo {
59-
return {
60-
testId: test.testId,
61-
name: test.name,
62-
parentNames: test.parentNames,
63-
testPath: test.testPath,
64-
project: test.project,
65-
type: test.type,
66-
location: test.location,
67-
tests: test.type === 'suite' ? test.tests.map(toTestInfo) : [],
68-
};
69-
}),
58+
tests: tests.map(toTestInfo),
7059
});
7160
runtime.instance.updateStatus('running');
7261

@@ -85,9 +74,23 @@ export function createRunner({ workerState }: { workerState: WorkerState }): {
8574
const tests = await runtime.instance.getTests();
8675
traverseUpdateTest(tests, testNamePattern);
8776

88-
return tests;
77+
return tests.map(toTestInfo);
8978
},
9079
getCurrentTest: () => testRunner.getCurrentTest(),
9180
},
9281
};
9382
}
83+
84+
function toTestInfo(test: Test): TestInfo {
85+
return {
86+
testId: test.testId,
87+
name: test.name,
88+
parentNames: test.parentNames,
89+
testPath: test.testPath,
90+
project: test.project,
91+
type: test.type,
92+
location: test.location,
93+
tests: test.type === 'suite' ? test.tests.map(toTestInfo) : [],
94+
runMode: test.runMode,
95+
};
96+
}

packages/core/src/runtime/runner/runner.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ export class TestRunner {
300300
testId: test.testId,
301301
type: 'suite',
302302
location: test.location,
303+
runMode: test.runMode,
303304
});
304305

305306
if (test.tests.length === 0) {
@@ -391,6 +392,7 @@ export class TestRunner {
391392
project: test.project,
392393
type: 'case',
393394
location: test.location,
395+
runMode: test.runMode,
394396
});
395397

396398
do {

packages/core/src/runtime/worker/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import type {
22
MaybePromise,
33
Rstest,
44
RunWorkerOptions,
5-
Test,
65
TestFileResult,
6+
TestInfo,
77
WorkerState,
88
} from '../../types';
99
import './setup';
10+
import type { FileCoverageData } from 'istanbul-lib-coverage';
1011
import { install } from 'source-map-support';
1112
import { createCoverageProvider } from '../../coverage';
1213
import { globalApis } from '../../utils/constants';
13-
import { color, undoSerializableConfig } from '../../utils/helper';
14+
import { color } from '../../utils/helper';
1415
import { formatTestError, getRealTimers, setRealTimers } from '../util';
1516
import { createForksRpcOptions, createRuntimeRpc } from './rpc';
1617
import { RstestSnapshotEnvironment } from './snapshot';
@@ -57,7 +58,6 @@ const preparePool = async ({
5758
context,
5859
}: RunWorkerOptions['options']) => {
5960
setRealTimers();
60-
context.runtimeConfig = undoSerializableConfig(context.runtimeConfig);
6161

6262
// Prefer public env var from tinypool, fallback to context.taskId
6363
process.env.RSTEST_WORKER_ID = String(
@@ -259,7 +259,7 @@ const runInPool = async (
259259
options: RunWorkerOptions['options'],
260260
): Promise<
261261
| {
262-
tests: Test[];
262+
tests: TestInfo[];
263263
testPath: string;
264264
}
265265
| TestFileResult
@@ -436,7 +436,12 @@ const runInPool = async (
436436
const coverageMap = coverageProvider.collect();
437437
if (coverageMap) {
438438
// Attach coverage data to test result
439-
results.coverage = coverageMap.toJSON();
439+
results.coverage = {};
440+
Object.entries(coverageMap.toJSON()).forEach(([key, value]) => {
441+
if ('toJSON' in value)
442+
results.coverage![key] = value.toJSON() as FileCoverageData;
443+
else results.coverage![key] = value;
444+
});
440445
}
441446
// Cleanup
442447
coverageProvider.cleanup();

0 commit comments

Comments
 (0)