fix(blob): store startTime as a number (#24620)

Turns out the Date objects have noticeable footprint on large suites and
storing them as umber is much cheaper, e.g.:


![image](https://github.com/microsoft/playwright/assets/9798949/539028d0-3ef8-46f7-be2b-752f24604d18)
This commit is contained in:
Yury Semikhatsky 2023-08-04 16:06:23 -07:00 committed by GitHub
parent aba6964bd1
commit 6c3142959d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 8 deletions

View File

@ -87,7 +87,7 @@ export type JsonTestResultStart = {
retry: number;
workerIndex: number;
parallelIndex: number;
startTime: string;
startTime: number;
};
export type JsonAttachment = Omit<TestResult['attachments'][0], 'body'> & { base64?: string };
@ -105,7 +105,7 @@ export type JsonTestStepStart = {
parentStepId?: string;
title: string;
category: string,
startTime: string;
startTime: number;
location?: Location;
};
@ -232,7 +232,7 @@ export class TeleReporterReceiver {
testResult.retry = payload.retry;
testResult.workerIndex = payload.workerIndex;
testResult.parallelIndex = payload.parallelIndex;
testResult.startTime = new Date(payload.startTime);
testResult.setStartTimeNumber(payload.startTime);
testResult.statusEx = 'running';
this._reporter.onTestBegin?.(test, testResult);
}
@ -510,22 +510,31 @@ class TeleTestStep implements TestStep {
category: string;
location: Location | undefined;
parent: TestStep | undefined;
startTime: Date;
duration: number = -1;
steps: TestStep[] = [];
private _startTime: number = 0;
constructor(payload: JsonTestStepStart, parentStep: TestStep | undefined, location: Location | undefined) {
this.title = payload.title;
this.category = payload.category;
this.location = location;
this.parent = parentStep;
this.startTime = new Date(payload.startTime);
this._startTime = payload.startTime;
}
titlePath() {
const parentPath = this.parent?.titlePath() || [];
return [...parentPath, this.title];
}
get startTime(): Date {
return new Date(this._startTime);
}
set startTime(value: Date) {
this._startTime = +value;
}
}
class TeleTestResult implements reporterTypes.TestResult {
@ -533,7 +542,6 @@ class TeleTestResult implements reporterTypes.TestResult {
parallelIndex: reporterTypes.TestResult['parallelIndex'] = -1;
workerIndex: reporterTypes.TestResult['workerIndex'] = -1;
duration: reporterTypes.TestResult['duration'] = -1;
startTime: reporterTypes.TestResult['startTime'] = new Date();
stdout: reporterTypes.TestResult['stdout'] = [];
stderr: reporterTypes.TestResult['stderr'] = [];
attachments: reporterTypes.TestResult['attachments'] = [];
@ -545,9 +553,23 @@ class TeleTestResult implements reporterTypes.TestResult {
stepMap: Map<string, reporterTypes.TestStep> = new Map();
statusEx: reporterTypes.TestResult['status'] | 'scheduled' | 'running' = 'scheduled';
private _startTime: number = 0;
constructor(retry: number) {
this.retry = retry;
}
setStartTimeNumber(startTime: number) {
this._startTime = startTime;
}
get startTime(): Date {
return new Date(this._startTime);
}
set startTime(value: Date) {
this._startTime = +value;
}
}
export type TeleFullProject = FullProject & { id: string };

View File

@ -199,7 +199,7 @@ export class TeleReporterEmitter implements ReporterV2 {
retry: result.retry,
workerIndex: result.workerIndex,
parallelIndex: result.parallelIndex,
startTime: result.startTime.toISOString(),
startTime: +result.startTime,
};
}
@ -229,7 +229,7 @@ export class TeleReporterEmitter implements ReporterV2 {
parentStepId: (step.parent as any)?.[idSymbol],
title: step.title,
category: step.category,
startTime: step.startTime.toISOString(),
startTime: +step.startTime,
location: this._relativeLocation(step.location),
};
}

View File

@ -48,6 +48,7 @@ class Reporter {
distillStep(step) {
return {
...step,
_startTime: undefined,
startTime: undefined,
duration: undefined,
parent: undefined,