Skip to content

Commit

Permalink
test(ssr): add styled/slot benchmarks (#4783)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Nov 7, 2024
1 parent b137d5d commit e9db491
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { renderComponent } from '@lwc/ssr-runtime';
import SlotUsage from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/slotUsageComponent/slotUsageComponent.js';
import Store from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/store/store.js';

const SSR_MODE = 'asyncYield';
const NUMBER_OF_ROWS = 5000;

benchmark(`ssr/slot/shadow/create/5k`, () => {
let store;
let rowsOfComponentWithSlot;
let rowsOfSlottedContent;

before(() => {
store = new Store();
rowsOfComponentWithSlot = store.buildData(NUMBER_OF_ROWS);
rowsOfSlottedContent = store.buildData(NUMBER_OF_ROWS);
});

run(() => {
const props = {
rows: store.data,
componentContent: 'Parent component slotting content to child cmp',
rowsOfSlottedContent: rowsOfSlottedContent,
titleOfComponentWithSlot: 'Component that receives a slot',
rowsOfComponentWithSlot: rowsOfComponentWithSlot,
};
return renderComponent('benchmark-slot-usage-component', SlotUsage, props, SSR_MODE);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import StyledComponent from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/light/styledComponent.js';

import { styledComponentSsrBenchmark } from '../../../utils/styledComponentSsrBenchmark';

const NUM_COMPONENTS = 10000;

// Create 10k components with the same CSS in each component
// These are light DOM components running in native mode
styledComponentSsrBenchmark(
`ssr/styled-component/light/create-same/10k`,
NUM_COMPONENTS,
StyledComponent,
{ after, before, benchmark, run }
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import components from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/light/styledComponents.js';

import { styledComponentSsrBenchmark } from '../../../utils/styledComponentSsrBenchmark';

const NUM_COMPONENTS = 1000;

// Create 1k components with different CSS in each component
// These are light DOM components running in native mode
styledComponentSsrBenchmark(
`ssr/styled-component/light/create-different/1k`,
NUM_COMPONENTS,
components,
{ after, before, benchmark, run }
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import StyledComponent from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/shadow/styledComponent.js';

import { styledComponentSsrBenchmark } from '../../../utils/styledComponentSsrBenchmark';

const NUM_COMPONENTS = 10000;

// Create 10k components with the same CSS in each component
styledComponentSsrBenchmark(
`ssr/styled-component/shadow/create-same/10k`,
NUM_COMPONENTS,
StyledComponent,
{ after, before, benchmark, run }
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import components from '@lwc/perf-benchmarks-components/dist/ssr/benchmark/shadow/styledComponents.js';

import { styledComponentSsrBenchmark } from '../../../utils/styledComponentSsrBenchmark';

const NUM_COMPONENTS = 1000;

// Create 1k components with different CSS in each component
styledComponentSsrBenchmark(
`ssr/styled-component/shadow/create-different/1k`,
NUM_COMPONENTS,
components,
{ after, before, benchmark, run }
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { renderComponent } from '@lwc/ssr-runtime';

const SSR_MODE = 'asyncYield';

// Generic benchmark for styled components, SSR-flavored!
export function styledComponentSsrBenchmark(
name,
numComponents,
componentOrComponents,
{ benchmark, run }
) {
benchmark(name, () => {
const isArray = Array.isArray(componentOrComponents);

run(async () => {
for (let i = 0; i < numComponents; i++) {
await renderComponent(
isArray ? `styled-component${i}` : 'styled-component',
isArray ? componentOrComponents[i] : componentOrComponents,
{},
SSR_MODE
);
}
});
});
}

0 comments on commit e9db491

Please sign in to comment.