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

feat(perf): hydrateComponent perf tests #2663

Merged
merged 4 commits into from
Jan 28, 2022
Merged

Conversation

jodarove
Copy link
Contributor

@jodarove jodarove commented Jan 27, 2022

Details

This PR adds the following perf tests for hydrateComponent:

  • table-hydrate-1k
  • tablecmp-hydrate-1k

SSR+hydrate vs createElement+appendChild:

For reference, I made a comparison of SSR+hydrate vs createElement+appendChild:

table 1k:

image

by modifying the perf test of hydrate, so it also includes the appendChild in the measures, this is the result:

image

modified test:

benchmark(`benchmark-table/hydrate/1k`, () => {
    let tableElement;
    let props;

    before(() => {
        const store = new Store();
        store.run();

        props = {
            title: 'table hydrate 1k',
            rows: store.data,
        };

        const ssrHtml = renderComponent('benchmark-table', Table, props);

        const fragment = new DOMParser().parseFromString(ssrHtml, 'text/html', {
            includeShadowRoots: true,
        });

        tableElement = fragment.querySelector('benchmark-table');
    });

    run(async () => {
        await insertComponent(tableElement); // <-- This is for reference only, the perf test should only measure hydrate.

        hydrateComponent(tableElement, TableClient, props);
    });
});

tablecmp 1k:

image

by modifying the perf test of hydrate, so it also includes the appendChild in the measures, this is the result:

image

modified test:

benchmark(`benchmark-table-component/hydrate/1k`, () => {
    let props;
    let tableElement;

    before(() => {
        const store = new Store();
        store.run();

        props = {
            rows: store.data,
        };

        const ssrHtml = renderComponent('benchmark-table', Table, props);

        const fragment = new DOMParser().parseFromString(ssrHtml, 'text/html', {
            includeShadowRoots: true,
        });

        tableElement = fragment.querySelector('benchmark-table');
    });

    run(async () => {
        await insertComponent(tableElement);
        hydrateComponent(tableElement, TableClient, props);
    });
});

First contentful paint

95.77ms - 103.65ms vs 146.62ms - 147.93ms. Note: for this measure, the perf test was slightly modified by removing all dataset generation and adding the ssr generated content in the html along with the rows, which is closer to a real example.

Does this pull request introduce a breaking change?

  • ✅ No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • ✅ No, it does not introduce an observable change.

Copy link
Collaborator

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants