Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: 优化开启多行文本时的布局性能 #2734

Merged
merged 7 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
96 changes: 85 additions & 11 deletions packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/* eslint-disable no-console */
import { PivotSheet, S2DataConfig } from '../../src';
import { PivotSheet, S2DataConfig, type S2Options } from '../../src';
import { generateRawData, getContainer } from '../util/helpers';

async function measurePivotSheetRender(s2DataCfg: S2DataConfig, title) {
async function measurePivotSheetRender(
title: string,
s2DataCfg: S2DataConfig,
s2Options?: S2Options,
) {
performance.mark('startTask');
const s2 = new PivotSheet(getContainer(), s2DataCfg, null);
const s2 = new PivotSheet(getContainer(), s2DataCfg, s2Options || null);

await s2.render();
performance.mark('endTask');
Expand All @@ -25,7 +29,7 @@
data: [],
};

test('should render 10 * 100', async () => {

Check warning on line 32 in packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Test has no assertions
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
Expand All @@ -40,12 +44,12 @@
};

await measurePivotSheetRender(
s2DataCfg,
'🚀 10 * 100 for single measure',
s2DataCfg,
);
});

test('should render 100 * 100', async () => {

Check warning on line 52 in packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Test has no assertions
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
Expand All @@ -60,12 +64,12 @@
};

await measurePivotSheetRender(
s2DataCfg,
'🚀 100 * 100 for single measure',
s2DataCfg,
);
});

test('should render 1000 * 100', async () => {

Check warning on line 72 in packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Test has no assertions
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
Expand All @@ -80,12 +84,12 @@
};

await measurePivotSheetRender(
s2DataCfg,
'🚀 1000 * 100 for single measure',
s2DataCfg,
);
});

test('should render 1000 * 1000', async () => {

Check warning on line 92 in packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Test has no assertions
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
Expand All @@ -100,8 +104,8 @@
};

await measurePivotSheetRender(
s2DataCfg,
'🚀 1000 * 1000 for single measure',
s2DataCfg,
);
});
});
Expand All @@ -116,7 +120,7 @@
data: [],
};

test('should render 10 * 100', async () => {

Check warning on line 123 in packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Test has no assertions
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
Expand All @@ -130,10 +134,10 @@
),
};

await measurePivotSheetRender(s2DataCfg, '🚀 10 * 100 for multi measure');
await measurePivotSheetRender('🚀 10 * 100 for multi measure', s2DataCfg);
});

test('should render 100 * 100', async () => {

Check warning on line 140 in packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Test has no assertions
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
Expand All @@ -148,12 +152,12 @@
};

await measurePivotSheetRender(
s2DataCfg,
'🚀 100 * 100 for multi measure',
s2DataCfg,
);
});

test('should render 1000 * 100', async () => {

Check warning on line 160 in packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Test has no assertions
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
Expand All @@ -168,12 +172,12 @@
};

await measurePivotSheetRender(
s2DataCfg,
'🚀 1000 * 100 for multi measure',
s2DataCfg,
);
});

test('should render 1000 * 1000', async () => {

Check warning on line 180 in packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Test has no assertions
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
Expand All @@ -188,8 +192,78 @@
};

await measurePivotSheetRender(
s2DataCfg,
'🚀 1000 * 1000 for multi measure',
s2DataCfg,
);
});
});

describe('multi line text', () => {
const baseDataCfg: S2DataConfig = {
fields: {
rows: ['province', 'city'],
columns: ['type', 'subType'],
values: ['number'],
},
data: [],
};

const s2Options: S2Options = {
style: {
cornerCell: {
maxLines: 3,
},
rowCell: {
maxLines: 3,
},
colCell: {
maxLines: 3,
},
dataCell: {
maxLines: 3,
},
},
};

test('should render 100 * 100', async () => {

Check warning on line 228 in packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Test has no assertions
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
[
['province', 10],
['city', 10],
['type', 10],
['subType', 10],
],
['number'],
),
};

await measurePivotSheetRender(
'🚀 100 * 100 for single measure',
s2DataCfg,
s2Options,
);
});

test('should render 1000 * 1000', async () => {

Check warning on line 249 in packages/s2-core/__tests__/benchmark/pivot-sheet-spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Test has no assertions
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
[
['province', 100],
['city', 10],
['type', 100],
['subType', 10],
],
['number'],
),
};

await measurePivotSheetRender(
'🚀 1000 * 1000 for single measure',
s2DataCfg,
s2Options,
);
});
});
Expand Down
65 changes: 58 additions & 7 deletions packages/s2-core/__tests__/benchmark/table-sheet-spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/* eslint-disable no-console */
import { S2DataConfig, TableSheet } from '../../src';
import { S2DataConfig, TableSheet, type S2Options } from '../../src';
import { generateRawData, getContainer } from '../util/helpers';

async function measureTableSheetRender(s2DataCfg: S2DataConfig, title) {
async function measureTableSheetRender(
title: string,
s2DataCfg: S2DataConfig,
s2Options?: S2Options,
) {
performance.mark('startTask');
const s2 = new TableSheet(getContainer(), s2DataCfg, null);
const s2 = new TableSheet(getContainer(), s2DataCfg, s2Options || null);

await s2.render();
performance.mark('endTask');
Expand Down Expand Up @@ -36,7 +40,7 @@ describe('table sheet benchmark', () => {
),
};

await measureTableSheetRender(s2DataCfg, '🚀 1000 items');
await measureTableSheetRender('🚀 1000 items', s2DataCfg);
});

test('should render 10000 items', async () => {
Expand All @@ -53,7 +57,7 @@ describe('table sheet benchmark', () => {
),
};

await measureTableSheetRender(s2DataCfg, '🚀 10000 items');
await measureTableSheetRender('🚀 10000 items', s2DataCfg);
});

test('should render 10_0000 items', async () => {
Expand All @@ -70,7 +74,7 @@ describe('table sheet benchmark', () => {
),
};

await measureTableSheetRender(s2DataCfg, '🚀 10_0000 items');
await measureTableSheetRender('🚀 10_0000 items', s2DataCfg);
});

test('should render 100_0000 items', async () => {
Expand All @@ -87,6 +91,53 @@ describe('table sheet benchmark', () => {
),
};

await measureTableSheetRender(s2DataCfg, '🚀 100_0000 items');
await measureTableSheetRender('🚀 100_0000 items', s2DataCfg);
});

describe('multi line text', () => {
const s2Options: S2Options = {
style: {
colCell: {
maxLines: 3,
},
dataCell: {
maxLines: 3,
},
},
};

test('should render 10_0000 items', async () => {
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
[
['province', 100],
['city', 10],
['type', 10],
['subType', 10],
],
['number'],
),
};

await measureTableSheetRender('🚀 10_0000 items', s2DataCfg, s2Options);
});

test('should render 100_0000 items', async () => {
const s2DataCfg: S2DataConfig = {
...baseDataCfg,
data: generateRawData(
[
['province', 100],
['city', 10],
['type', 100],
['subType', 10],
],
['number'],
),
};

await measureTableSheetRender('🚀 100_0000 items', s2DataCfg, s2Options);
});
});
});
Loading
Loading