Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

perf: cache component variables #2041

Merged
merged 8 commits into from
Oct 18, 2019
Merged

Conversation

miroslavstastny
Copy link
Member

Do not resolve component variables in each render.

Resolved variables are now cached in ProviderContext. Nested Provider starts with an empty cache.

Performance:

Example Avg Median
Chat.perf BEFORE 491.65 439.58
Chat.perf AFTER 436.13 397.77

@@ -168,4 +168,5 @@ export interface ProviderContextPrepared {
target: Document
theme: ThemePrepared
originalThemes: (ThemeInput | undefined)[]
resolvedComponentVariables: Record<string, object>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
resolvedComponentVariables: Record<string, object>
DO_NOT_USE_OR_YOU_WILL_BE_FIRED_resolvedComponentVariables: Record<string, object>

Copy link
Member Author

Choose a reason for hiding this comment

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

would _internal_resolvedComponentVariables be enough?

Copy link
Member Author

@miroslavstastny miroslavstastny Oct 18, 2019

Choose a reason for hiding this comment

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

renamed

props.variables && withDebugId(props.variables, 'props.variables'),
)(theme.siteVariables)
// Resolve variables for this component, cache the result in provider
if (!(displayName in resolvedComponentVariables)) {
Copy link
Member

@layershifter layershifter Oct 18, 2019

Choose a reason for hiding this comment

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

Suggested change
if (!(displayName in resolvedComponentVariables)) {
if (!resolvedComponentVariables[displayName]) {

If there difference between this?

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, they are completely opposite :-P

other than that, yes:
image

but because of the || {} on line 183, this is no longer necessary

Copy link
Member Author

Choose a reason for hiding this comment

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

removed

resolvedComponentVariables[displayName],
withDebugId(props.variables, 'props.variables'),
)(theme.siteVariables)
: resolvedComponentVariables[displayName]
Copy link
Member

Choose a reason for hiding this comment

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

nit, it's hard to read this, I suggest

let resolvedVariables = resolvedComponentVariables[displayName]

if (props.variables) {
  resolvedVariables = mergeComponentVariables(
    resolvedComponentVariables[displayName],
    withDebugId(props.variables, 'props.variables'),
  )(theme.siteVariables)
}

Copy link
Member Author

@miroslavstastny miroslavstastny Oct 18, 2019

Choose a reason for hiding this comment

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

I don't like let.

@miroslavstastny miroslavstastny merged commit 6027c78 into master Oct 18, 2019
@miroslavstastny miroslavstastny deleted the perf/cache-component-variables branch October 18, 2019 13:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants