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

Dashboard Performance: HtmlContent improvements #4726

Merged
merged 2 commits into from
Mar 15, 2020

Conversation

gabrieldutra
Copy link
Member

What type of PR is this? (check all applicable)

  • Other

Description

Second PR for #4714, basically all widgets had this component rendered unnecessarily (also it could be memoized as its props should always return the same component). Although the sanitize function is kinda of performant, I believe it scales with the number of renders and widgets.

Individual improvement (based on master)

Dashboard master This PR % of improvement
Sales Dashboard 3599 ms 2859 ms 20%
Dashboard for testing React migration 42505 ms 37854 ms 10%

(The performance analysis were run with the same time for each dashboard twice (with the least value selected) to make sure results more reliable.)

The Scripting time I'm noting actually varies considerably, but when there's an actual improvement, the minimum value you can get diminishes, so it's been the best benchmark I've found so far. It just makes it a bit more difficult to measure dashboards with low avg scripting time (< 3s).

Related Tickets & Documents

#4714

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

--

return (
<div
{...props}
dangerouslySetInnerHTML={{ __html: sanitize(children) }} // eslint-disable-line react/no-danger
/>
);
}
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you tried to use useMemo instead of React.memo? React.memo changes behavior of component (due to shallow comparison of props, component may not properly react to props changes):

const html = useMemo(() => ({ __html: sanitize(children) }), [children]);

return <div {...props} dangerouslySetInnerHTML={html} />

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, useMemo should have the same performance in concept, but not re-rendering the component at all looked better. For the HtmlContent component it should be totally dependent on its props. I quickly checked its usages, it has only an string for className (basic variable types don't create issues with shallow comparison) and the children node didn't seem a problem as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for explanation! While I personally prefer useMemo, React.memo looks good as well 👍

</HtmlContent>
{!isEmpty(widget.getQuery().description) && (
<HtmlContent className="text-muted markdown query--description">
{markdown.toHTML(widget.getQuery().description || "")}
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about markdown.toHTML performance? Is it fast enough, or maybe also needs some caching?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't cache it with useMemo because it runs widget.getQuery() currently, it would need to have the widget as a dependency. Since that component is basically re-rendered when widgetchanges, that didn't seem that relevant 🤔. Also now it only runs that function when the query has a description.

@arikfr arikfr merged commit f675042 into master Mar 15, 2020
@arikfr arikfr deleted the dashboard-performance--memoize-htmlcontent branch March 15, 2020 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants